foscat 3.1.6__tar.gz → 3.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. foscat-3.3.0/LICENCE +13 -0
  2. foscat-3.3.0/PKG-INFO +177 -0
  3. foscat-3.3.0/README.md +155 -0
  4. foscat-3.3.0/pyproject.toml +85 -0
  5. foscat-3.3.0/setup.cfg +4 -0
  6. foscat-3.3.0/src/foscat/CNN.py +151 -0
  7. foscat-3.3.0/src/foscat/CircSpline.py +75 -0
  8. foscat-3.3.0/src/foscat/FoCUS.py +2706 -0
  9. foscat-3.3.0/src/foscat/GCNN.py +239 -0
  10. {foscat-3.1.6 → foscat-3.3.0}/src/foscat/Softmax.py +27 -22
  11. foscat-3.3.0/src/foscat/Spline1D.py +92 -0
  12. foscat-3.3.0/src/foscat/Synthesis.py +455 -0
  13. foscat-3.3.0/src/foscat/alm.py +134 -0
  14. foscat-3.3.0/src/foscat/backend.py +1024 -0
  15. foscat-3.3.0/src/foscat/backend_tens.py +63 -0
  16. foscat-3.3.0/src/foscat/loss_backend_tens.py +70 -0
  17. foscat-3.3.0/src/foscat/loss_backend_torch.py +58 -0
  18. foscat-3.3.0/src/foscat/scat.py +2030 -0
  19. foscat-3.3.0/src/foscat/scat1D.py +1546 -0
  20. foscat-3.3.0/src/foscat/scat2D.py +17 -0
  21. foscat-3.3.0/src/foscat/scat_cov.py +3794 -0
  22. foscat-3.3.0/src/foscat/scat_cov1D.py +18 -0
  23. foscat-3.3.0/src/foscat/scat_cov2D.py +18 -0
  24. foscat-3.3.0/src/foscat/scat_cov_map.py +93 -0
  25. foscat-3.3.0/src/foscat/scat_cov_map2D.py +94 -0
  26. foscat-3.3.0/src/foscat.egg-info/PKG-INFO +177 -0
  27. {foscat-3.1.6 → foscat-3.3.0}/src/foscat.egg-info/SOURCES.txt +3 -4
  28. foscat-3.1.6/PKG-INFO +0 -23
  29. foscat-3.1.6/README.md +0 -61
  30. foscat-3.1.6/setup.cfg +0 -8
  31. foscat-3.1.6/setup.py +0 -27
  32. foscat-3.1.6/src/foscat/CNN.py +0 -112
  33. foscat-3.1.6/src/foscat/CircSpline.py +0 -51
  34. foscat-3.1.6/src/foscat/FoCUS.py +0 -1990
  35. foscat-3.1.6/src/foscat/GCNN.py +0 -172
  36. foscat-3.1.6/src/foscat/GetGPUinfo.py +0 -36
  37. foscat-3.1.6/src/foscat/Spline1D.py +0 -42
  38. foscat-3.1.6/src/foscat/Synthesis.py +0 -386
  39. foscat-3.1.6/src/foscat/backend.py +0 -851
  40. foscat-3.1.6/src/foscat/backend_tens.py +0 -49
  41. foscat-3.1.6/src/foscat/loss_backend_tens.py +0 -60
  42. foscat-3.1.6/src/foscat/loss_backend_torch.py +0 -84
  43. foscat-3.1.6/src/foscat/scat.py +0 -1450
  44. foscat-3.1.6/src/foscat/scat1D.py +0 -1130
  45. foscat-3.1.6/src/foscat/scat2D.py +0 -15
  46. foscat-3.1.6/src/foscat/scat_cov.py +0 -2693
  47. foscat-3.1.6/src/foscat/scat_cov1D.old.py +0 -1547
  48. foscat-3.1.6/src/foscat/scat_cov1D.py +0 -16
  49. foscat-3.1.6/src/foscat/scat_cov2D.py +0 -16
  50. foscat-3.1.6/src/foscat/scat_cov_map.py +0 -67
  51. foscat-3.1.6/src/foscat/scat_cov_map2D.py +0 -64
  52. foscat-3.1.6/src/foscat.egg-info/PKG-INFO +0 -23
  53. {foscat-3.1.6 → foscat-3.3.0}/src/foscat/__init__.py +0 -0
  54. {foscat-3.1.6 → foscat-3.3.0}/src/foscat.egg-info/dependency_links.txt +0 -0
  55. {foscat-3.1.6 → foscat-3.3.0}/src/foscat.egg-info/requires.txt +0 -0
  56. {foscat-3.1.6 → foscat-3.3.0}/src/foscat.egg-info/top_level.txt +0 -0
foscat-3.3.0/LICENCE ADDED
@@ -0,0 +1,13 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2022, the Foscat developers All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+
9
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10
+
11
+ Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
foscat-3.3.0/PKG-INFO ADDED
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.1
2
+ Name: foscat
3
+ Version: 3.3.0
4
+ Summary: Generate synthetic Healpix or 2D data using Cross Scattering Transform
5
+ Author-email: Jean-Marc DELOUIS <jean.marc.delouis@ifremer.fr>
6
+ Maintainer-email: Theo Foulquier <theo.foulquier@ifremer.fr>
7
+ License: BSD-3-Clause
8
+ Project-URL: Repository, https://github.com/jmdelouis/FOSCAT.git
9
+ Project-URL: Issues, https://github.com/jmdelouis/FOSCAT/issues
10
+ Project-URL: Documentation, https://foscat-documentation.readthedocs.io/en/latest/index.html
11
+ Keywords: scattering transform,component separation,denoising
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENCE
22
+
23
+ # foscat
24
+
25
+ [![Read the Docs](https://readthedocs.org/projects/foscat-documentation/badge/?version=latest)](https://foscat-documentation.readthedocs.io/en/latest)
26
+
27
+ A python package dedicated to image component separation based on scattering transform analysis designed for high performance computing.
28
+
29
+ ## the concept
30
+
31
+ The foscat genesis has been built to synthesise data (2D or Healpix) using Cross Scattering Transform. For a detailed method description please refer to https://arxiv.org/abs/2207.12527. This algorithm could be effectively usable for component separation (e.g. denoising).
32
+
33
+ A demo package for this process can be found at https://github.com/jmdelouis/FOSCAT_DEMO.
34
+
35
+ ## usage
36
+
37
+ # Short tutorial
38
+
39
+ https://github.com/IAOCEA/demo-foscat-pangeo-eosc/blob/main/Demo_Synthesis.ipynb
40
+
41
+ # FOSCAT_DEMO
42
+
43
+ The python scripts _demo.py_ included in this package demonstrate how to use the foscat library to generate synthetic fields that have patterns with the same statistical properties as a specified image.
44
+
45
+ # Install foscat library
46
+
47
+ Before installing, make sure you have python installed in your enviroment.
48
+ The last version of the foscat library can be installed using PyPi:
49
+
50
+ ```
51
+ pip install foscat
52
+ ```
53
+
54
+ Load the FOSCAT_DEMO package from github.
55
+
56
+ ```
57
+ git clone https://github.com/jmdelouis/FOSCAT_DEMO.git
58
+ ```
59
+
60
+ ## Recommended installing procedures for mac users
61
+
62
+ It is recomended to use python=3.9\*.
63
+
64
+ ```
65
+ micromamba create -n FOSCAT
66
+ micromamba install -n FOSCAT ‘python==3.9*’
67
+ micromamba activate FOSCAT
68
+ pip install foscat
69
+ git clone https://github.com/jmdelouis/FOSCAT_DEMO.git
70
+
71
+ ```
72
+
73
+ ## Recommended installing procedures HPC users
74
+
75
+ It is recomended to install tensorflow in advance. For [DATARMOR](https://pcdm.ifremer.fr/Equipement) for using GPU ;
76
+
77
+ ```
78
+ micromamba create -n FOSCAT
79
+ micromamba install -n FOSCAT ‘python==3.9*’
80
+ micromamba install -n FOSCAT ‘tensorflow==2.11.0’
81
+ micromamba activate FOSCAT
82
+ pip install foscat
83
+ git clone https://github.com/jmdelouis/FOSCAT_DEMO.git
84
+
85
+ ```
86
+
87
+ # Spherical data example
88
+
89
+ ## compute a synthetic image
90
+
91
+ ```
92
+ python demo.py -n=32 -k -c -s=100
93
+ ```
94
+
95
+ The _demo.py_ script serves as a demonstration of the capabilities of the foscat library. It utilizes the Cross Wavelet Scattering Transform to generate a Healpix map that possesses the same characteristics as a specified input map.
96
+
97
+ - `-n=32` computes map with nside=32.
98
+ - `-k` uses 5x5 kernel.
99
+ - `-c` uses Scattering Covariance.
100
+ - `-l` uses LBFGS minimizer.
101
+ - `-s=100` computes 100 steps.
102
+
103
+ ```
104
+ python demo.py -n=8 [-c|--cov][-s|--steps=3000][-S=1234|--seed=1234][-k|--k5x5][-d|--data][-o|--out][-r|--orient] [-p|--path][-a|--adam]
105
+
106
+ ```
107
+
108
+ - The "-n" option specifies the nside of the input map. The maximum nside value is 256 with the default map.
109
+ - The "--cov" option (optional) uses scat_cov instead of scat.
110
+ - The "--steps" option (optional) specifies the number of iterations. If not specified, the default value is 1000.
111
+ - The "--seed" option (optional) specifies the seed of the random generator.
112
+ - The "--path" option (optional) allows you to define the path where the output files will be written. The default path is "data".
113
+ - The "--k5x5" option (optional) uses a 5x5 kernel instead of a 3x3.
114
+ - The "--data" option (optional) specifies the input data file to be used. If not specified, the default file "LSS_map_nside128.npy" will be used.
115
+ - The "--out" option (optional) specifies the output file name. If not specified, the output file will be saved in "demo".
116
+ - The "--orient" option (optional) specifies the number of orientations. If not specified, the default value is 4.
117
+ - The "--adam" option (optional) makes the synthesis using the ADAM optimizer instead of the L_BFGS.
118
+
119
+ ## plot the result
120
+
121
+ The following script generates a series of plots that showcase different aspects of the synthesis process using the _demo.py_ script.
122
+
123
+ > python test2D.py
124
+
125
+ ```
126
+ python plotdemo.py -n=32 -c
127
+ ```
128
+
129
+ # 2D field demo
130
+
131
+ > python test2Dplot.py
132
+
133
+ # compute a synthetic turbulent field
134
+
135
+ The python scripts _demo2D.py_ included in this package demonstrate how to use the foscat library to generate a 2D synthetic fields that have patterns with the same statistical properties as a specified 2D image. In this particular case, the input field is a sea surface temperature extracted from a north atlantic ocean simulation.
136
+
137
+ > python testHealpix.py
138
+
139
+ ```
140
+ python demo2d.py -n=32 -k -c
141
+ ```
142
+
143
+ > python testHplot.py
144
+
145
+ The following script generates a series of plots that showcase different aspects of the synthesis process using the _demo2D.py_ script.
146
+
147
+ ```
148
+ python plotdemo2d.py -n=32 -c
149
+ ```
150
+
151
+ For more information, see the [documentation](https://foscat-documentation.readthedocs.io/en/latest/index.html).
152
+
153
+ > mpirun -np 3 testHealpix_mpi.py
154
+
155
+ ## Authors and acknowledgment
156
+
157
+ Authors: J.-M. Delouis, P. Campeti, T. Foulquier, J. Mangin, L. Mousset, T. Odaka, F. Paul, E. Allys
158
+
159
+ This work is part of the R & T Deepsee project supported by CNES. The authors acknowledge the heritage of the Planck-HFI consortium regarding data, software, knowledge. This work has been supported by the Programme National de Télédétection Spatiale (PNTS, http://programmes.insu.cnrs.fr/pnts/), grant n◦ PNTS-2020-08
160
+
161
+ ## License
162
+
163
+ BSD 3-Clause License
164
+
165
+ Copyright (c) 2022, the Foscat developers All rights reserved.
166
+
167
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
168
+
169
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
170
+
171
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
172
+
173
+ Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
174
+
175
+ ## Project status
176
+
177
+ It is a scientific driven development. We are open to any contributing development.
foscat-3.3.0/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # foscat
2
+
3
+ [![Read the Docs](https://readthedocs.org/projects/foscat-documentation/badge/?version=latest)](https://foscat-documentation.readthedocs.io/en/latest)
4
+
5
+ A python package dedicated to image component separation based on scattering transform analysis designed for high performance computing.
6
+
7
+ ## the concept
8
+
9
+ The foscat genesis has been built to synthesise data (2D or Healpix) using Cross Scattering Transform. For a detailed method description please refer to https://arxiv.org/abs/2207.12527. This algorithm could be effectively usable for component separation (e.g. denoising).
10
+
11
+ A demo package for this process can be found at https://github.com/jmdelouis/FOSCAT_DEMO.
12
+
13
+ ## usage
14
+
15
+ # Short tutorial
16
+
17
+ https://github.com/IAOCEA/demo-foscat-pangeo-eosc/blob/main/Demo_Synthesis.ipynb
18
+
19
+ # FOSCAT_DEMO
20
+
21
+ The python scripts _demo.py_ included in this package demonstrate how to use the foscat library to generate synthetic fields that have patterns with the same statistical properties as a specified image.
22
+
23
+ # Install foscat library
24
+
25
+ Before installing, make sure you have python installed in your enviroment.
26
+ The last version of the foscat library can be installed using PyPi:
27
+
28
+ ```
29
+ pip install foscat
30
+ ```
31
+
32
+ Load the FOSCAT_DEMO package from github.
33
+
34
+ ```
35
+ git clone https://github.com/jmdelouis/FOSCAT_DEMO.git
36
+ ```
37
+
38
+ ## Recommended installing procedures for mac users
39
+
40
+ It is recomended to use python=3.9\*.
41
+
42
+ ```
43
+ micromamba create -n FOSCAT
44
+ micromamba install -n FOSCAT ‘python==3.9*’
45
+ micromamba activate FOSCAT
46
+ pip install foscat
47
+ git clone https://github.com/jmdelouis/FOSCAT_DEMO.git
48
+
49
+ ```
50
+
51
+ ## Recommended installing procedures HPC users
52
+
53
+ It is recomended to install tensorflow in advance. For [DATARMOR](https://pcdm.ifremer.fr/Equipement) for using GPU ;
54
+
55
+ ```
56
+ micromamba create -n FOSCAT
57
+ micromamba install -n FOSCAT ‘python==3.9*’
58
+ micromamba install -n FOSCAT ‘tensorflow==2.11.0’
59
+ micromamba activate FOSCAT
60
+ pip install foscat
61
+ git clone https://github.com/jmdelouis/FOSCAT_DEMO.git
62
+
63
+ ```
64
+
65
+ # Spherical data example
66
+
67
+ ## compute a synthetic image
68
+
69
+ ```
70
+ python demo.py -n=32 -k -c -s=100
71
+ ```
72
+
73
+ The _demo.py_ script serves as a demonstration of the capabilities of the foscat library. It utilizes the Cross Wavelet Scattering Transform to generate a Healpix map that possesses the same characteristics as a specified input map.
74
+
75
+ - `-n=32` computes map with nside=32.
76
+ - `-k` uses 5x5 kernel.
77
+ - `-c` uses Scattering Covariance.
78
+ - `-l` uses LBFGS minimizer.
79
+ - `-s=100` computes 100 steps.
80
+
81
+ ```
82
+ python demo.py -n=8 [-c|--cov][-s|--steps=3000][-S=1234|--seed=1234][-k|--k5x5][-d|--data][-o|--out][-r|--orient] [-p|--path][-a|--adam]
83
+
84
+ ```
85
+
86
+ - The "-n" option specifies the nside of the input map. The maximum nside value is 256 with the default map.
87
+ - The "--cov" option (optional) uses scat_cov instead of scat.
88
+ - The "--steps" option (optional) specifies the number of iterations. If not specified, the default value is 1000.
89
+ - The "--seed" option (optional) specifies the seed of the random generator.
90
+ - The "--path" option (optional) allows you to define the path where the output files will be written. The default path is "data".
91
+ - The "--k5x5" option (optional) uses a 5x5 kernel instead of a 3x3.
92
+ - The "--data" option (optional) specifies the input data file to be used. If not specified, the default file "LSS_map_nside128.npy" will be used.
93
+ - The "--out" option (optional) specifies the output file name. If not specified, the output file will be saved in "demo".
94
+ - The "--orient" option (optional) specifies the number of orientations. If not specified, the default value is 4.
95
+ - The "--adam" option (optional) makes the synthesis using the ADAM optimizer instead of the L_BFGS.
96
+
97
+ ## plot the result
98
+
99
+ The following script generates a series of plots that showcase different aspects of the synthesis process using the _demo.py_ script.
100
+
101
+ > python test2D.py
102
+
103
+ ```
104
+ python plotdemo.py -n=32 -c
105
+ ```
106
+
107
+ # 2D field demo
108
+
109
+ > python test2Dplot.py
110
+
111
+ # compute a synthetic turbulent field
112
+
113
+ The python scripts _demo2D.py_ included in this package demonstrate how to use the foscat library to generate a 2D synthetic fields that have patterns with the same statistical properties as a specified 2D image. In this particular case, the input field is a sea surface temperature extracted from a north atlantic ocean simulation.
114
+
115
+ > python testHealpix.py
116
+
117
+ ```
118
+ python demo2d.py -n=32 -k -c
119
+ ```
120
+
121
+ > python testHplot.py
122
+
123
+ The following script generates a series of plots that showcase different aspects of the synthesis process using the _demo2D.py_ script.
124
+
125
+ ```
126
+ python plotdemo2d.py -n=32 -c
127
+ ```
128
+
129
+ For more information, see the [documentation](https://foscat-documentation.readthedocs.io/en/latest/index.html).
130
+
131
+ > mpirun -np 3 testHealpix_mpi.py
132
+
133
+ ## Authors and acknowledgment
134
+
135
+ Authors: J.-M. Delouis, P. Campeti, T. Foulquier, J. Mangin, L. Mousset, T. Odaka, F. Paul, E. Allys
136
+
137
+ This work is part of the R & T Deepsee project supported by CNES. The authors acknowledge the heritage of the Planck-HFI consortium regarding data, software, knowledge. This work has been supported by the Programme National de Télédétection Spatiale (PNTS, http://programmes.insu.cnrs.fr/pnts/), grant n◦ PNTS-2020-08
138
+
139
+ ## License
140
+
141
+ BSD 3-Clause License
142
+
143
+ Copyright (c) 2022, the Foscat developers All rights reserved.
144
+
145
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
146
+
147
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
148
+
149
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
150
+
151
+ Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
152
+
153
+ ## Project status
154
+
155
+ It is a scientific driven development. We are open to any contributing development.
@@ -0,0 +1,85 @@
1
+ [project]
2
+ name = "foscat"
3
+ version = "3.3.0"
4
+ description = "Generate synthetic Healpix or 2D data using Cross Scattering Transform"
5
+ readme = "README.md"
6
+ license = { text = "BSD-3-Clause" }
7
+ authors = [
8
+ { name = "Jean-Marc DELOUIS", email = "jean.marc.delouis@ifremer.fr" },
9
+ ]
10
+ maintainers = [
11
+ { name = "Theo Foulquier", email = "theo.foulquier@ifremer.fr" },
12
+ ]
13
+ dependencies = [
14
+ "imageio",
15
+ "imagecodecs",
16
+ "matplotlib",
17
+ "numpy",
18
+ "tensorflow",
19
+ "healpy",
20
+ ]
21
+ requires-python = ">= 3.9"
22
+ keywords = ["scattering transform", "component separation", "denoising"]
23
+ classifiers = [
24
+ "Intended Audience :: Science/Research",
25
+ "License :: OSI Approved :: MIT License",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3.9",
28
+ "Programming Language :: Python :: 3.10",
29
+ "Programming Language :: Python :: 3.11",
30
+ "Programming Language :: Python :: 3.12",
31
+ ]
32
+
33
+ [project.urls]
34
+ Repository = "https://github.com/jmdelouis/FOSCAT.git"
35
+ Issues = "https://github.com/jmdelouis/FOSCAT/issues"
36
+ Documentation = "https://foscat-documentation.readthedocs.io/en/latest/index.html"
37
+
38
+ [tool.setuptools]
39
+ package-dir = { "" = "src" }
40
+ packages = ["foscat"]
41
+
42
+ [build-system]
43
+ requires = ["setuptools"]
44
+ build-backend = "setuptools.build_meta"
45
+
46
+ [tool.ruff]
47
+ target-version = "py39"
48
+ builtins = ["ellipsis"]
49
+ exclude = [
50
+ ".git",
51
+ ".eggs",
52
+ "build",
53
+ "dist",
54
+ "__pycache__",
55
+ ]
56
+ line-length = 100
57
+
58
+ [tool.ruff.lint]
59
+ ignore = [
60
+ "E402", # E402: module level import not at top of file
61
+ "E501", # E501: line too long - let black worry about that
62
+ "E731", # E731: do not assign a lambda expression, use a def
63
+ # ignore for now, fix in a later PR
64
+ "E722", # bare except
65
+ "UP031", # percent-based string interpolation
66
+ ]
67
+ select = [
68
+ "F", # Pyflakes
69
+ "E", # Pycodestyle
70
+ "I", # isort
71
+ "UP", # Pyupgrade
72
+ "TID", # flake8-tidy-imports
73
+ "W",
74
+ ]
75
+ extend-safe-fixes = [
76
+ "TID252", # absolute imports
77
+ ]
78
+ fixable = ["I", "TID252"]
79
+
80
+ [tool.ruff.lint.isort]
81
+ known-first-party = ["foscat"]
82
+
83
+ [tool.ruff.lint.flake8-tidy-imports]
84
+ # Disallow all relative imports.
85
+ ban-relative-imports = "all"
foscat-3.3.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,151 @@
1
+ import pickle
2
+
3
+ import numpy as np
4
+
5
+ import foscat.scat_cov as sc
6
+
7
+
8
+ class CNN:
9
+
10
+ def __init__(
11
+ self,
12
+ scat_operator=None,
13
+ nparam=1,
14
+ nscale=1,
15
+ chanlist=[],
16
+ in_nside=1,
17
+ n_chan_in=1,
18
+ nbatch=1,
19
+ SEED=1234,
20
+ filename=None,
21
+ ):
22
+
23
+ if filename is not None:
24
+ outlist = pickle.load(open("%s.pkl" % (filename), "rb"))
25
+ self.scat_operator = sc.funct(KERNELSZ=outlist[3], all_type=outlist[7])
26
+ self.KERNELSZ = self.scat_operator.KERNELSZ
27
+ self.all_type = self.scat_operator.all_type
28
+ self.npar = outlist[2]
29
+ self.nscale = outlist[5]
30
+ self.chanlist = outlist[0]
31
+ self.in_nside = outlist[4]
32
+ self.nbatch = outlist[1]
33
+ self.n_chan_in = outlist[8]
34
+ self.x = self.scat_operator.backend.bk_cast(outlist[6])
35
+ self.out_nside = self.in_nside // (2**self.nscale)
36
+ else:
37
+ self.nscale = nscale
38
+ self.nbatch = nbatch
39
+ self.npar = nparam
40
+ self.n_chan_in = n_chan_in
41
+ self.scat_operator = scat_operator
42
+ if len(chanlist) != nscale + 1:
43
+ print(
44
+ "len of chanlist (here %d) should of nscale+1 (here %d)"
45
+ % (len(chanlist), nscale + 1)
46
+ )
47
+ return None
48
+
49
+ self.chanlist = chanlist
50
+ self.KERNELSZ = scat_operator.KERNELSZ
51
+ self.all_type = scat_operator.all_type
52
+ self.in_nside = in_nside
53
+ self.out_nside = self.in_nside // (2**self.nscale)
54
+
55
+ np.random.seed(SEED)
56
+ self.x = scat_operator.backend.bk_cast(
57
+ np.random.randn(self.get_number_of_weights())
58
+ / (self.KERNELSZ * self.KERNELSZ)
59
+ )
60
+
61
+ def save(self, filename):
62
+
63
+ outlist = [
64
+ self.chanlist,
65
+ self.nbatch,
66
+ self.npar,
67
+ self.KERNELSZ,
68
+ self.in_nside,
69
+ self.nscale,
70
+ self.get_weights().numpy(),
71
+ self.all_type,
72
+ self.n_chan_in,
73
+ ]
74
+
75
+ myout = open("%s.pkl" % (filename), "wb")
76
+ pickle.dump(outlist, myout)
77
+ myout.close()
78
+
79
+ def get_number_of_weights(self):
80
+ totnchan = 0
81
+ for i in range(self.nscale):
82
+ totnchan = totnchan + self.chanlist[i] * self.chanlist[i + 1]
83
+ return (
84
+ self.npar * 12 * self.out_nside**2 * self.chanlist[self.nscale]
85
+ + totnchan * self.KERNELSZ * self.KERNELSZ
86
+ + self.KERNELSZ * self.KERNELSZ * self.n_chan_in * self.chanlist[0]
87
+ )
88
+
89
+ def set_weights(self, x):
90
+ self.x = x
91
+
92
+ def get_weights(self):
93
+ return self.x
94
+
95
+ def eval(self, im, indices=None, weights=None):
96
+
97
+ x = self.x
98
+ ww = self.scat_operator.backend.bk_reshape(
99
+ x[0 : self.KERNELSZ * self.KERNELSZ * self.n_chan_in * self.chanlist[0]],
100
+ [self.KERNELSZ * self.KERNELSZ, self.n_chan_in, self.chanlist[0]],
101
+ )
102
+ nn = self.KERNELSZ * self.KERNELSZ * self.n_chan_in * self.chanlist[0]
103
+
104
+ im = self.scat_operator.healpix_layer(im, ww)
105
+ im = self.scat_operator.backend.bk_relu(im)
106
+
107
+ for k in range(self.nscale):
108
+ ww = self.scat_operator.backend.bk_reshape(
109
+ x[
110
+ nn : nn
111
+ + self.KERNELSZ
112
+ * self.KERNELSZ
113
+ * self.chanlist[k]
114
+ * self.chanlist[k + 1]
115
+ ],
116
+ [self.KERNELSZ * self.KERNELSZ, self.chanlist[k], self.chanlist[k + 1]],
117
+ )
118
+ nn = (
119
+ nn
120
+ + self.KERNELSZ
121
+ * self.KERNELSZ
122
+ * self.chanlist[k]
123
+ * self.chanlist[k + 1]
124
+ )
125
+ if indices is None:
126
+ im = self.scat_operator.healpix_layer(im, ww)
127
+ else:
128
+ im = self.scat_operator.healpix_layer(
129
+ im, ww, indices=indices[k], weights=weights[k]
130
+ )
131
+ im = self.scat_operator.backend.bk_relu(im)
132
+ im = self.scat_operator.ud_grade_2(im, axis=0)
133
+
134
+ ww = self.scat_operator.backend.bk_reshape(
135
+ x[
136
+ nn : nn
137
+ + self.npar * 12 * self.out_nside**2 * self.chanlist[self.nscale]
138
+ ],
139
+ [12 * self.out_nside**2 * self.chanlist[self.nscale], self.npar],
140
+ )
141
+
142
+ im = self.scat_operator.backend.bk_matmul(
143
+ self.scat_operator.backend.bk_reshape(
144
+ im, [1, 12 * self.out_nside**2 * self.chanlist[self.nscale]]
145
+ ),
146
+ ww,
147
+ )
148
+ im = self.scat_operator.backend.bk_reshape(im, [self.npar])
149
+ im = self.scat_operator.backend.bk_relu(im)
150
+
151
+ return im
@@ -0,0 +1,75 @@
1
+ import numpy as np
2
+
3
+
4
+ class CircSpline:
5
+ def __init__(self, nodes, degree=3):
6
+ """
7
+ Initializes the Spline1D instance.
8
+
9
+ Parameters:
10
+ - nodes (int): The number of nodes in the spline.
11
+ - degree (int): The degree of the spline. Default is 3.
12
+ """
13
+ self.degree = degree
14
+ self.nodes = nodes
15
+
16
+
17
+ def cubic_spline_function(self,x):
18
+ """
19
+ Evaluate the cubic spline basis function.
20
+
21
+ Args:
22
+ x (float or array): Input value(s) to evaluate the spline basis function.
23
+
24
+ Returns:
25
+ float or array: Result of the cubic spline basis function.
26
+ """
27
+ return -2 * x**3 + 3 * x**2
28
+
29
+
30
+ def eval(self,x):
31
+ """
32
+ Compute a 3rd-degree cubic spline with 4-point support.
33
+
34
+ Args:
35
+ x (float or array): Input value(s) to compute the spline.
36
+
37
+ Returns:
38
+ indices (array): Indices of the spline support points.
39
+ coefficients (array): Normalized spline coefficients.
40
+ """
41
+ N=self.nodes
42
+
43
+ if isinstance(x, float):
44
+ # Single scalar input
45
+ base_idx = int(x * (N))
46
+ indices = np.zeros([4], dtype="int")
47
+ coefficients = np.zeros([4])
48
+ else:
49
+ # Array input
50
+ base_idx = (x * (N)).astype("int")
51
+ indices = np.zeros([4, x.shape[0]], dtype="int")
52
+ coefficients = np.zeros([4, x.shape[0]])
53
+
54
+ # Compute the fractional part of the input
55
+ fractional_part = x * (N) - base_idx
56
+
57
+ # Compute spline coefficients for 4 support points
58
+ coefficients[3] = self.cubic_spline_function(fractional_part / 2) / 2
59
+ coefficients[2] = self.cubic_spline_function(0.5 + fractional_part / 2) / 2
60
+ coefficients[1] = self.cubic_spline_function(1 - fractional_part / 2) / 2
61
+ coefficients[0] = self.cubic_spline_function(0.5 - fractional_part / 2) / 2
62
+
63
+ # Assign indices for the support points
64
+ indices[3] = (base_idx + 3)%N
65
+ indices[2] = (base_idx + 2)%N
66
+ indices[1] = (base_idx + 1)%N
67
+ indices[0] = base_idx
68
+
69
+ # Adjust indices to start from 0
70
+ indices = indices - 1
71
+ # Square coefficients and normalize
72
+ coefficients = coefficients * coefficients
73
+ coefficients /= np.sum(coefficients, axis=0)
74
+
75
+ return indices, coefficients