diff --git a/CHANGELOG b/CHANGELOG index 5a0154cc5854851d605781f5d146a1dcd1a299eb..9a5b110fd0620a70b6a309c91481f6262fa34268 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -533,3 +533,9 @@ v2.12 Support running CSO within a virtual environment. + +v2.13 +----- + +Updates for latest python versions. +Improved error checks. diff --git a/README.md b/README.md index a22bda9c240ecece4285e3377818fb8cc0647be5..5f3c04f2330ddbd9670dbd45f4512bc91cae5830 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,39 @@ When finished, leave from the virtual environment using: deactivate +Eventually create the following script that activates the envioronment, +or creates it if not present yet: + + # + # Source this script to setup: + # + # . this_script + # + + # virtual environment exists already? + if [ -f .venv/bin/activate ]; then + + # activate: + source .venv/bin/activate + + else + + # eventually enable latest python version: + #module load python/3.13.1 + + # init virtual environment: + python3 -m venv --prompt cso .venv + + # activate: + source .venv/bin/activate + + # upgrade pip: + pip install --upgrade pip + + # install local codes: + pip install --editable . + + fi diff --git a/doc/source/history.rst b/doc/source/history.rst index d643e088f3df8dc0284432f545bd48a7d2a54651..9294260129788f8d23c55d2c3887f368bd8c697d 100644 --- a/doc/source/history.rst +++ b/doc/source/history.rst @@ -118,6 +118,9 @@ A summary of the versions and changes. * | *v2.12* | Support running in Python virtual environment. + +* | *v2.13* + | Minor updates to trap errors and support latest Python versions. To be included @@ -159,7 +162,7 @@ A wishlist of developments. How to create a version tag =========================== -Example for tag "v2.12". +Example for tag "v2.13". 1. Update file formatting following conventions. @@ -179,17 +182,17 @@ Example for tag "v2.12". c. Change the release tag that will also be imported to the documenation in the `pyproject.toml <../../../pyproject.toml>`_ file:: - release = "2.12" + release = "2.13" d. Commit and push these changes:: - git commit -m 'Defined v2.12' . + git commit -m 'Defined v2.13' . git push 4. Tag and push the code to the git repository:: - git tag -a 'v2.12' -m 'Tagged v2.12' - git push origin v2.12 + git tag -a 'v2.13' -m 'Tagged v2.13' + git push origin v2.13 diff --git a/pyproject.toml b/pyproject.toml index 42d3905d362db84364c18b3055befae78c5fbba5..3ed4cacb9de4683d26701a5b0ce77990f45d53b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "cso" -version = "2.12" +version = "2.13" authors = [ { name = "Arjo Segers" }, { name = "Lewis Blake" }, diff --git a/src/cso/cso_file.py b/src/cso/cso_file.py index b1f2d854a3f54aad86b9ab85265ac8f06067da6c..aa59f5dd5a1108d68040674eaa50e5a1f3b3e52d 100644 --- a/src/cso/cso_file.py +++ b/src/cso/cso_file.py @@ -58,6 +58,9 @@ # 2025-10, Arjo Segers # Replace ' and ' by ' & ' when selecting records. # +# 2026-01, Arjo Segers +# Updated use of Dataset.dims following deprication warning. +# ######################################################################## ### @@ -1128,7 +1131,7 @@ class CSO_File(object): logging.info(indent + "pixel selection ...") # init selection, by default accept all: - selected = numpy.ones((self.ds.dims["pixel"],), "bool") + selected = numpy.ones((self.ds.sizes["pixel"],), "bool") # init history: history = [] diff --git a/src/cso/cso_mapping.py b/src/cso/cso_mapping.py index e23f3df1f6b5af87a04846945293c12644147aaf..fe95bb71d062253aaff32679bdc8b5c9c2ebbdae 100644 --- a/src/cso/cso_mapping.py +++ b/src/cso/cso_mapping.py @@ -14,6 +14,9 @@ # 2023-08, Arjo Segers # Remove rounding errors when locations are very close. # +# 2026-01, Arjo Segers +# Changed imports for python packaging. +# ######################################################################## ### @@ -89,7 +92,7 @@ def LonLatDistance(lon1, lat1, lon2, lat2): import numpy # tools: - from cso_constants import EarthRadius + from . import cso_constants # convert: delta = lon2 - lon1 @@ -102,7 +105,7 @@ def LonLatDistance(lon1, lat1, lon2, lat2): phi = numpy.arccos(x.clip(-1.0, 1.0)) # radians # in m over the globe: - return phi * EarthRadius # m + return phi * cso_constants.EarthRadius # m # enddef # LonLatDistance @@ -176,7 +179,7 @@ def LonLatTrianglesArea(xx, yy): import numpy # tools: - from cso_constants import EarthRadius + from . import cso_constants # areas: aa = TrianglesArea(numpy.radians(xx), numpy.radians(yy)) # rad2 @@ -186,7 +189,7 @@ def LonLatTrianglesArea(xx, yy): # areas: # rad2 m2 - return aa * numpy.cos(yy_aver) * EarthRadius**2 # m2 + return aa * numpy.cos(yy_aver) * cso_constants.EarthRadius**2 # m2 # enddef LonLatTrianglesArea diff --git a/src/cso/cso_s5p.py b/src/cso/cso_s5p.py index 602bdf3a3a5276f58b054ebbe3cdb8fb2891f190..c20275de7bdf90e97dee4964062dcc97786ed63c 100644 --- a/src/cso/cso_s5p.py +++ b/src/cso/cso_s5p.py @@ -74,6 +74,10 @@ # Trap multiple selections from inquire table as this might indicate # a problem in the table or the selection. # +# 2026-01, Arjo Segers +# Updated use of Dataset.dims following deprication warning. +# Explicitly defined data type in encoding of time array folowing warning. +# ######################################################################## @@ -223,9 +227,9 @@ class S5p_File(object): self.nscan = ds.sizes["scanline"] self.ngpix = ds.sizes["ground_pixel"] # number 'atmoshpere' layers: - if "layer" in ds.dims.keys(): + if "layer" in ds.dims: self.nlayer = ds.sizes["layer"] - elif "level" in ds.dims.keys(): + elif "level" in ds.dims: self.nlayer = ds.sizes["level"] else: self.nlayer = None @@ -1408,6 +1412,7 @@ class CSO_S5p_File(cso_file.CSO_File): da.attrs["long_name"] = "time" da.encoding["calendar"] = "standard" da.encoding["units"] = f"seconds since {t0.year}-01-01 00:00:000" + da.encoding["dtype"] = "float64" # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # pixel corners: for longitudes, need to ensure that also near dateline diff --git a/src/cso/cso_superobs.py b/src/cso/cso_superobs.py index 4e18e4cdbdbd8131b7e16b8d57193ce6cc6e8db3..aec6d443cac3ae870aa1d7f8bc0ed811b95d8c83 100644 --- a/src/cso/cso_superobs.py +++ b/src/cso/cso_superobs.py @@ -24,6 +24,12 @@ # 2025-04, Arjo Segers # Changed imports for python packaging. # +# 2026-01, Arjo Segers +# Explicitly defined data type in encoding of time array folowing warning. +# +# 2026-01, Alessandro D'ausilio +# Trap case that no pixels are selected. +# ######################################################################## @@ -350,18 +356,20 @@ class CSO_SuperObs(utopya.UtopyaRc): source_file = cso_file.CSO_File(filename=source_filename) # filter: - selected, history = source_file.SelectPixels( - self.rcf, rcbase, indent=indent + " " - ) + selected, history = source_file.SelectPixels(self.rcf, rcbase, indent=f"{indent} ") # info .. - logging.info( - indent + " selected %i / %i pixels .." % (selected.sum(), selected.size) - ) + logging.info(f"{indent} selected {selected.sum()} / {selected.size} pixels ..") # selected indices: (iipix,) = numpy.where(selected) # number of selected pixels: npix = len(iipix) + # check .. + if npix == 0: + logging.info(f"{indent} no pixels selected, skip ...") + continue + #endif + # footprint or points? if wtype == "number": # info ... @@ -738,6 +746,7 @@ class CSO_SuperObs(utopya.UtopyaRc): # ensure correct output: outf.ds[vkey].encoding["units"] = tunits outf.ds[vkey].encoding["calendar"] = "standard" + outf.ds[vkey].encoding["dtype"] = "float64" outf.ds[vkey].encoding["_FillValue"] = None else: diff --git a/src/utopya/utopya_build.py b/src/utopya/utopya_build.py index e5c02e4b70131f55182823d601e4ee50fee464fe..7be5b31f92c62b6c99f167f94e9f2c5925d4cb21 100644 --- a/src/utopya/utopya_build.py +++ b/src/utopya/utopya_build.py @@ -222,10 +222,10 @@ class UtopyaCopy(utopya_rc.UtopyaRc): see the initialization of the :py:class:`.UtopyaRc` class for details and the necessary configuration of the logging system. - If the *'new'* flag is present it overwrites the *'\*.copy.new'* flag; - set to '*True'* to remove an existing build directory if present. + If the ``new`` flag is present it overwrites the ``copy.new`` rcfile setting; + set to ``True`` to remove an existing build directory if present. - The following example shows the required settings for an rcbase *'optm'*. + The following example shows the required settings for an rcbase ``optm``. The content of the directories:: sources/model/base/src