Git Product home page Git Product logo

python-geotiepoints's People

Contributors

adybbroe avatar avalentino avatar dependabot[bot] avatar djhoese avatar helgedmi avatar mitkin avatar mraspaud avatar pepephillips avatar pnuu avatar sjoro avatar stickler-ci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-geotiepoints's Issues

Test failure with scipy 1.13.x

Code Sample, a minimal, complete, and verifiable piece of code

$ python3.12 -m pytest --pyargs geotiepoints

Problem description

Tests of the unit test suite fail.

Expected Output

All tests pass successfully,

Actual Result, Traceback if applicable

============================= test session starts ==============================
platform linux -- Python 3.12.4, pytest-8.2.2, pluggy-1.5.0
rootdir: /home/antonio/debian/git/build-area/python-geotiepoints-1.7.4/.pybuild/cpython3_3.12_geotiepoints/build
configfile: pyproject.toml
plugins: cov-5.0.0
collected 45 items

geotiepoints/tests/test_geointerpolator.py ............                  [ 26%]
geotiepoints/tests/test_interpolator.py ....FFFF.                        [ 46%]
geotiepoints/tests/test_modis.py .sss                                    [ 55%]
geotiepoints/tests/test_modisinterpolator.py ssssssss                    [ 73%]
geotiepoints/tests/test_multilinear.py .                                 [ 75%]
geotiepoints/tests/test_satelliteinterpolator.py ..                      [ 80%]
geotiepoints/tests/test_simple_modis_interpolator.py sssssss             [ 95%]
geotiepoints/tests/test_viiinterpolator.py ..                            [100%]

=================================== FAILURES ===================================
_________________ TestSingleGridInterpolator.test_interpolate __________________

self = <geotiepoints.tests.test_interpolator.TestSingleGridInterpolator object at 0x7aefe19ef4d0>
grid_interpolator = <geotiepoints.interpolator.SingleGridInterpolator object at 0x7aefe0f19ee0>

    def test_interpolate(self, grid_interpolator):
        """Test that interpolation is working."""
        fine_x = np.arange(16)
        fine_y = np.arange(32)
    
        res = grid_interpolator.interpolate((fine_y, fine_x), method=CUBIC_LEGACY)
>       np.testing.assert_allclose(res, self.expected, atol=2e-9)

geotiepoints/tests/test_interpolator.py:359: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<function assert_allclose.<locals>.compare at 0x7aefe0f3b380>, array([[ 0.00000000e+00,  5.91632075e-01,  9.09670897e...4.00000000e+00,  4.00000000e+00,
         4.00000000e+00,  4.00000000e+00,  4.00000000e+00,
         4.00000000e+00]]))
kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-07, atol=2e-09', 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Not equal to tolerance rtol=1e-07, atol=2e-09
E           
E           Mismatched elements: 506 / 512 (98.8%)
E           Max absolute difference: 0.00011739
E           Max relative difference: 2.57232271e+11
E            x: array([[ 0.000000e+00,  5.916321e-01,  9.096709e-01,  9.999468e-01,
E                    9.082902e-01,  6.805314e-01,  3.625007e-01,  2.855852e-05,
E                   -3.610547e-01, -6.749188e-01, -8.957333e-01, -9.776679e-01,...
E            y: array([[ 0.000000e+00,  5.916667e-01,  9.097222e-01,  1.000000e+00,
E                    9.083333e-01,  6.805556e-01,  3.625000e-01,  1.110223e-16,
E                   -3.611111e-01, -6.750000e-01, -8.958333e-01, -9.777778e-01,...

/usr/lib/python3.12/contextlib.py:81: AssertionError
______________ TestSingleGridInterpolator.test_interpolate_slices ______________

self = <geotiepoints.tests.test_interpolator.TestSingleGridInterpolator object at 0x7aefe19ef680>
grid_interpolator = <geotiepoints.interpolator.SingleGridInterpolator object at 0x7aefe0c05490>

    def test_interpolate_slices(self, grid_interpolator):
        """Test that interpolation from slices is working."""
        res = grid_interpolator.interpolate_slices((slice(0, 32), slice(0, 16)), method=CUBIC_LEGACY)
>       np.testing.assert_allclose(res, self.expected, atol=2e-9)

geotiepoints/tests/test_interpolator.py:364: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<function assert_allclose.<locals>.compare at 0x7aefe0f399e0>, array([[ 0.00000000e+00,  5.91632075e-01,  9.09670897e...4.00000000e+00,  4.00000000e+00,
         4.00000000e+00,  4.00000000e+00,  4.00000000e+00,
         4.00000000e+00]]))
kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-07, atol=2e-09', 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Not equal to tolerance rtol=1e-07, atol=2e-09
E           
E           Mismatched elements: 506 / 512 (98.8%)
E           Max absolute difference: 0.00011739
E           Max relative difference: 2.57232271e+11
E            x: array([[ 0.000000e+00,  5.916321e-01,  9.096709e-01,  9.999468e-01,
E                    9.082902e-01,  6.805314e-01,  3.625007e-01,  2.855852e-05,
E                   -3.610547e-01, -6.749188e-01, -8.957333e-01, -9.776679e-01,...
E            y: array([[ 0.000000e+00,  5.916667e-01,  9.097222e-01,  1.000000e+00,
E                    9.083333e-01,  6.805556e-01,  3.625000e-01,  1.110223e-16,
E                   -3.611111e-01, -6.750000e-01, -8.958333e-01, -9.777778e-01,...

/usr/lib/python3.12/contextlib.py:81: AssertionError
____ TestSingleGridInterpolator.test_interpolate_dask[10-expected_chunks0] _____

self = <geotiepoints.tests.test_interpolator.TestSingleGridInterpolator object at 0x7aefe19ef920>
grid_interpolator = <geotiepoints.interpolator.SingleGridInterpolator object at 0x7aefe0f4fe90>
chunks = 10, expected_chunks = (10, 10)

    @pytest.mark.parametrize("chunks, expected_chunks", [(10, (10, 10)),
                                                         ((10, 5), (10, 5))])
    def test_interpolate_dask(self, grid_interpolator, chunks, expected_chunks):
        """Test that interpolation with dask is working."""
        da = pytest.importorskip("dask.array")
    
        fine_x = np.arange(16)
        fine_y = np.arange(32)
    
        with mock.patch.object(grid_interpolator,
                               "interpolate_numpy",
                               wraps=grid_interpolator.interpolate_numpy) as interpolate:
            res = grid_interpolator.interpolate((fine_y, fine_x), method=CUBIC_LEGACY, chunks=chunks)
            assert not interpolate.called
    
            assert isinstance(res, da.Array)
            v_chunk, h_chunk = expected_chunks
            assert res.chunks[0][0] == v_chunk
            assert res.chunks[1][0] == h_chunk
    
>           np.testing.assert_allclose(res, self.expected, atol=2e-9)

geotiepoints/tests/test_interpolator.py:386: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<function assert_allclose.<locals>.compare at 0x7aefe0f3bb00>, array([[ 0.00000000e+00,  5.91632075e-01,  9.09670897e...4.00000000e+00,  4.00000000e+00,
         4.00000000e+00,  4.00000000e+00,  4.00000000e+00,
         4.00000000e+00]]))
kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-07, atol=2e-09', 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Not equal to tolerance rtol=1e-07, atol=2e-09
E           
E           Mismatched elements: 506 / 512 (98.8%)
E           Max absolute difference: 0.00011739
E           Max relative difference: 2.57232271e+11
E            x: array([[ 0.000000e+00,  5.916321e-01,  9.096709e-01,  9.999468e-01,
E                    9.082902e-01,  6.805314e-01,  3.625007e-01,  2.855852e-05,
E                   -3.610547e-01, -6.749188e-01, -8.957333e-01, -9.776679e-01,...
E            y: array([[ 0.000000e+00,  5.916667e-01,  9.097222e-01,  1.000000e+00,
E                    9.083333e-01,  6.805556e-01,  3.625000e-01,  1.110223e-16,
E                   -3.611111e-01, -6.750000e-01, -8.958333e-01, -9.777778e-01,...

/usr/lib/python3.12/contextlib.py:81: AssertionError
__ TestSingleGridInterpolator.test_interpolate_dask[chunks1-expected_chunks1] __

self = <geotiepoints.tests.test_interpolator.TestSingleGridInterpolator object at 0x7aefe19eff20>
grid_interpolator = <geotiepoints.interpolator.SingleGridInterpolator object at 0x7aefe03d70e0>
chunks = (10, 5), expected_chunks = (10, 5)

    @pytest.mark.parametrize("chunks, expected_chunks", [(10, (10, 10)),
                                                         ((10, 5), (10, 5))])
    def test_interpolate_dask(self, grid_interpolator, chunks, expected_chunks):
        """Test that interpolation with dask is working."""
        da = pytest.importorskip("dask.array")
    
        fine_x = np.arange(16)
        fine_y = np.arange(32)
    
        with mock.patch.object(grid_interpolator,
                               "interpolate_numpy",
                               wraps=grid_interpolator.interpolate_numpy) as interpolate:
            res = grid_interpolator.interpolate((fine_y, fine_x), method=CUBIC_LEGACY, chunks=chunks)
            assert not interpolate.called
    
            assert isinstance(res, da.Array)
            v_chunk, h_chunk = expected_chunks
            assert res.chunks[0][0] == v_chunk
            assert res.chunks[1][0] == h_chunk
    
>           np.testing.assert_allclose(res, self.expected, atol=2e-9)

geotiepoints/tests/test_interpolator.py:386: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<function assert_allclose.<locals>.compare at 0x7aefe03f2ac0>, array([[ 0.00000000e+00,  5.91632075e-01,  9.09670897e...4.00000000e+00,  4.00000000e+00,
         4.00000000e+00,  4.00000000e+00,  4.00000000e+00,
         4.00000000e+00]]))
kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-07, atol=2e-09', 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Not equal to tolerance rtol=1e-07, atol=2e-09
E           
E           Mismatched elements: 506 / 512 (98.8%)
E           Max absolute difference: 0.00011739
E           Max relative difference: 2.57232271e+11
E            x: array([[ 0.000000e+00,  5.916321e-01,  9.096709e-01,  9.999468e-01,
E                    9.082902e-01,  6.805314e-01,  3.625007e-01,  2.855852e-05,
E                   -3.610547e-01, -6.749188e-01, -8.957333e-01, -9.776679e-01,...
E            y: array([[ 0.000000e+00,  5.916667e-01,  9.097222e-01,  1.000000e+00,
E                    9.083333e-01,  6.805556e-01,  3.625000e-01,  1.110223e-16,
E                   -3.611111e-01, -6.750000e-01, -8.958333e-01, -9.777778e-01,...

/usr/lib/python3.12/contextlib.py:81: AssertionError
=============================== warnings summary ===============================
geotiepoints/tests/test_geointerpolator.py::TestGeoGridInterpolator::test_geogrid_interpolation_can_extrapolate
  /home/antonio/debian/git/build-area/python-geotiepoints-1.7.4/.pybuild/cpython3_3.12_geotiepoints/build/geotiepoints/geointerpolator.py:82: RuntimeWarning: invalid value encountered in arcsin
    lats = np.sign(z__) * (90 - np.rad2deg(np.arcsin(np.sqrt(x__ ** 2 + y__ ** 2) / radius)))

geotiepoints/tests/test_multilinear.py::TestMultilinearInterpolator::test_multilinear_interp
  /home/antonio/debian/git/build-area/python-geotiepoints-1.7.4/.pybuild/cpython3_3.12_geotiepoints/build/geotiepoints/tests/test_multilinear.py:75: RuntimeWarning: invalid value encountered in power
    np.power(x[0, :]**3 + x[1, :]**3, 1.0 / 3.0)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED geotiepoints/tests/test_interpolator.py::TestSingleGridInterpolator::test_interpolate
FAILED geotiepoints/tests/test_interpolator.py::TestSingleGridInterpolator::test_interpolate_slices
FAILED geotiepoints/tests/test_interpolator.py::TestSingleGridInterpolator::test_interpolate_dask[10-expected_chunks0]
FAILED geotiepoints/tests/test_interpolator.py::TestSingleGridInterpolator::test_interpolate_dask[chunks1-expected_chunks1]
============= 4 failed, 23 passed, 18 skipped, 2 warnings in 3.82s =============

Versions of Python, package at hand and relevant dependencies

  • Python v3.12.4
  • scipy v1.13.1
  • geotiepoints v1.7.4
  • OS: GNU/Linux Debian sid
  • Arch x86_64

Interpolation of MODIS lat/lons is incorrect

Code Sample, a minimal, complete, and verifiable piece of code

from satpy import Scene
import numpy as np
mod_03_file = 'MYD03.A2013046.0100.061.2018044025952.hdf'
mod_06_file = 'MYD06_L2.A2013046.0100.061.2018044213021.hdf'

scn_m3 = Scene([mod_03_file], reader='modis_l1b')
scn_m3.load(['latitude', 'longitude'], resolution=1000)
lats = np.array(scn_m3['latitude'].data)
lons = np.array(scn_m3['longitude'].data)
# This print statement gives the correct lats / lons
print("GOOD")
print(np.nanmin(lons),
        np.nanmean(lons),
        np.nanmax(lons))

scn_m6 = Scene([mod_06_file], reader='modis_l2')
scn_m6.load(['latitude', 'longitude'], resolution=1000)
lats = np.array(scn_m6['latitude'].data)
lons = np.array(scn_m6['longitude'].data)
# This print statement gives the wrong lats / lons
print("BAD")
print(np.nanmin(lons),
        np.nanmean(lons),
        np.nanmax(lons))

Problem description

The MODIS level 1 and level 2 files contain geoinformation (lat, lon, etc) at 5km resolution, while much of the data is at 1km resolution.
I'm using Satpy to read this data, and the resampling from 5km to 1km is done automagically by geotiepoints. However, when a MODIS granule crosses the dateline the interpolation is incorrect. If a granule doesn't cross the dateline then the interpolation seems to work OK, differences between the interpolated lat/lon and the lat/lon from the MYD03 file are within floating point rounding errors.
The above example, that uses the MYD06 product (containing info at 5km) and the MYD03 product (with geoinfo at 1km) shows the issue.
Output from the above is:

GOOD
-179.99994 -167.00832 179.99998
BAD
-504.3378248021475 -167.00175882007775 953.9804062453378

I don't understand the code well enough to figure out what's happening, but hopefully you can use the above to diagnose. You can download the above files from https://search.earthdata.nasa.gov/search
The granules are from 01:00 UTC on 15th Feb 2013.

Help wanted: verify the interpolation of MERSI-2 1000M GEO to 250M GEO

National Meteorological Satellite Center's public website has stopped the distrubution of MERSI-2 L1B 250M GEO files for unkown reasons. So I tried to use GeoInterpolator to interpolate 1000m lat/lon to 250m. The result image looks good but I still want to have an original 250M to verify my operation. @mraspaud @djhoese If you guys can still have access to 250M GEO files, could you help me to get one? Time node is 20230613_0615. Thanks!

When I install this package,it said 'Failed building wheel for python-geotiepoints'.

Cython will not be used. Use environment variable 'USE_CYTHON=True' to use it
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\geotiepoints
copying geotiepoints\basic_interpolator.py -> build\lib.win-amd64-3.6\geotiepo
ints
copying geotiepoints\geointerpolator.py -> build\lib.win-amd64-3.6\geotiepoint
s
copying geotiepoints\interpolator.py -> build\lib.win-amd64-3.6\geotiepoints
copying geotiepoints\multilinear.py -> build\lib.win-amd64-3.6\geotiepoints
copying geotiepoints\version.py -> build\lib.win-amd64-3.6\geotiepoints
copying geotiepoints_init_.py -> build\lib.win-amd64-3.6\geotiepoints
running build_ext
building 'geotiepoints.multilinear_cython' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C+

This are the whole errors

When I installed Microsoft Visual C++ 2017,there are the same errors.
I don't know how to install it.

MNT: Stop using ci-helpers in appveyor.yml

To whom it may concern,

If you are using https://github.com/astropy/ci-helpers in your appveyor.yml , please know that the Astropy project has dropped active development/support for Appveyor CI. If it still works, good for you, because we did not remove the relevant files (yet). But if it ever stops working, we have no plans to fix anything for Appveyor CI. Please consider using native Windows support other CI, e.g., Travis CI (see https://docs.travis-ci.com/user/reference/windows/). We apologize for any inconvenience caused.

If this issue is opened in error or irrelevant to you, feel free to close. Thank you.

xref astropy/ci-helpers#464

5-dimensional interpolation

Is there any reason that the upper limit is 4D? If I am reading the code correctly, there appears to be cython code for 5D interpolation in geotiepoints/multilinear_cython.pyx, but this has not been compiled into geotiepoints/multilinear_cython.c.

Thanks!

ValueError from _extrapolate_rows

I've just come across this project and it looks exactly what I was after, but I'm getting an error when doing the interpolation. I've checked out the code and unit tests are failing with the same problem.

For example tests.test_geointerpolator.test_fill_row_borders fails with:

Error
Traceback (most recent call last):
  File "/Users/watson-parris/miniconda3/envs/cis_dev/lib/python2.7/unittest/case.py", line 329, in run
    testMethod()
  File "/Users/watson-parris/PycharmProjects/python-geotiepoints/tests/test_geointerpolator.py", line 137, in test_fill_row_borders
    satint._fill_row_borders()
  File "/Users/watson-parris/PycharmProjects/python-geotiepoints/geotiepoints/interpolator.py", line 222, in _fill_row_borders
    self.hrow_indices[index + chunk_size - 1])
  File "/Users/watson-parris/PycharmProjects/python-geotiepoints/geotiepoints/interpolator.py", line 186, in _extrapolate_rows
    pos = row_indices[:2]
ValueError: cannot slice a 0-d array

and the tests.test_geointerpolator.test_extrapolate_rows test fails with:

Error
Traceback (most recent call last):
  File "/Users/watson-parris/miniconda3/envs/cis_dev/lib/python2.7/unittest/case.py", line 329, in run
    testMethod()
  File "/Users/watson-parris/PycharmProjects/python-geotiepoints/tests/test_geointerpolator.py", line 119, in test_extrapolate_rows
    self.assertTrue(np.allclose(satint._extrapolate_rows(satint.tie_data[0]),
TypeError: _extrapolate_rows() takes exactly 5 arguments (2 given)

Did you perhaps not push all the changes when you made the last commit?

Thanks

MODIS Interpolation Comparisons

While working on my 3 PRs for optimizing MODIS interpolation (#35, #36, #38), I noticed that in real world cases my cython-based PRs were producing invalid/bad images where the bow-tie pixels of an image were clearly being mapped incorrectly from the default interpolation used by Satpy (the geotiepoints/modisinterpolator.py version that uses the CVIIRS algorithm). This happens even though the unit tests pass! This means that the tests aren't strict/rigid enough in their thresholds to the point that they let invalid/bad results through.

NOTE: All plots/images in this issue were made with the current main branch and don't use my updated code.

I've since been trying to do a deep dive on what is going on and how the "simple" interpolation compares to the CVIIRS interpolation. I've discovered at least one problem with the last column of the data. Here is a zoomed in view of the differences between the two methods' longitude arrays, specifically the upper right corner, when used on real Aqua data:

image

You may be able to see on the right most columns (where I've removed the black border line in the matplotlib plot) that the differences are suddenly much higher for the last column. If I look at the individual plots for these longitudes I can't see anything obvious in either method's results. I'll post the images I've generated so far to start the discussion, but we need to come up with ways to decide which method to use as "truth".

Note I refer to the CVIIRS algorithm as "angle-based" because it requires solar zenith angles. I refer to the other method as "simple" because it pretty close to basic bilinear interpolation from the basic understanding I have.

geotiepoints_interp_anglebased
geotiepoints_interp_differences
geotiepoints_interp_simple

CC @simonrp84

Docstring headers still include authors.

python-geotiepoints docstring headers still include authors. Should these follow the new notation used in Satpy?

Example:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2018 PyTroll community
# Author(s):
#   Martin Raspaud <[email protected]>
# ....

Problem description

Docstring headers not in line with Satpy.

Expected Output

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2019 Python-geotiepoints developers
#
# This file is part of python-geotiepoints.
#
# python-geotiepoints is free software: you can redistribute it and/or modify it under the
# terms .....

C extension does not compile on py3.9 without re-cythonizing

Building master fails on cpython 3.9.1:

geotiepoints/multilinear_cython.c:24742:26: error: no member named 'tp_print' in
'struct _typeobject'
__pyx_type___pyx_array.tp_print = 0;
~~~~~~~~~~~~~~~~~~~~~~ ^
geotiepoints/multilinear_cython.c:24747:32: error: no member named 'tp_print' in
'struct _typeobject'
__pyx_type___pyx_MemviewEnum.tp_print = 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
geotiepoints/multilinear_cython.c:24762:31: error: no member named 'tp_print' in
'struct _typeobject'
__pyx_type___pyx_memoryview.tp_print = 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
geotiepoints/multilinear_cython.c:24775:36: error: no member named 'tp_print' in
'struct _typeobject'
__pyx_type___pyx_memoryviewslice.tp_print = 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^

Removing geotiepoints/multilinear_cython.c and running cythonize -3 multilinear_cython.pyx appears to fix the issue .... (Cython 0.29.21)

I saw #4 and while on one hand pre-generating the C source does make it possible to install w/o Cython, I'm not sure that Cython was designed around that idea?

Make the interpolators dask-compatible

Problem description

At the moment, most of the interpolator aren't dask-friendly, which in turn necessitates a lots of workarounds in the code using geotiepoints.

This is a feature request to make geotiepoints as dask-compatible as possible. Supporting xarray.DataArrays would also be nice.

Add link to VII documentation.

viiinterpolator is a prototype based on documentation that is not at this time publicly available. Link to the documentation should be added once documentation is published.

I'm trying to install pycups on mac os using the treminal, but I'm getting “building wheel for pycups (setup.py) … error”

$pip install pycups
Collecting pycups
Using cached pycups-2.0.1.tar.gz (62 kB)
Building wheels for collected packages: pycups
Building wheel for pycups (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-
install-_itolwzg/pycups_229a8ad4200041038747d41d5862ab4c/setup.py'"'"'; file='"'"'/tmp/pip-
install-_itolwzg/pycups_229a8ad4200041038747d41d5862ab4c/setup.py'"'"';f=getattr(tokenize,
'"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"',
'"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-
29ml6iuu
cwd: /tmp/pip-install-_itolwzg/pycups_229a8ad4200041038747d41d5862ab4c/
Complete output (165 lines):
running bdist_wheel
running build
running build_ext
building 'cups' extension
creating build
creating build/temp.linux-x86_64-3.6
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DVERSION="2.0.1" -
I/usr/local/include/python3.6m -c cupsmodule.c -o build/temp.linux-x86_64-3.6/cupsmodule.o
cupsmodule.c: In function 'cups_enumDests':
cupsmodule.c:422: warning: implicit declaration of function 'cupsEnumDests'
cupsmodule.c: In function 'cups_connectDest':
cupsmodule.c:501: warning: implicit declaration of function 'cupsConnectDest'
cupsmodule.c:508: warning: assignment makes pointer from integer without a cast
cupsmodule.c: In function 'PyInit_cups':
cupsmodule.c:919: error: 'HTTP_STATUS_ERROR' undeclared (first use in this function)
cupsmodule.c:919: error: (Each undeclared identifier is reported only once
cupsmodule.c:919: error: for each function it appears in.)
.....
....
.....
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for pycups
Running setup.py clean for pycups
Failed to build pycups

Upgrade to Cython 3.0 and check annotations

Cython 3 has come out and there are a lot of big changes. I've run into a couple gotchas so far and we'll need to be careful. I think we should make sure to force cython>=3 in the pyproject.toml. Issues I've run into so far:

  1. DEF/constants are being deprecated. See cython/cython#4310. However, I haven't found good replacements for some of the use cases so I'm not sure this is the first thing we tackle.
  2. cdef functions now default to exceptions being possible (as if you had done except -1 or similar). For many cases of the code I write this isn't what I want. On nogil functions this is extra bad because it adds a GIL acquire and release to check the error state. The fix is to do noexcept nogil: at the end of the function declaration. Checking the HTML output of cython -a some_module.pyx makes it pretty clear since our nogil functions shouldn't have any yellow (non-C code).
  3. We can and should probably drop the old numpy API by defining in setup.py:
        define_macros = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]

Issues with interpolation on a Sentinel Tie Point Grid.

Code Sample, a minimal, complete, and verifiable piece of code

tie_cols = np.arange(
    1, image_data.shape[0], math.ceil(image_data.shape[0] / longitude.shape[1])
)
print(tie_cols.shape)
fine_cols = np.arange(image_data.shape[1])

tie_rows = np.arange(
    1, image_data.shape[1], math.ceil(image_data.shape[1] / latitude.shape[0])
)
print(tie_rows.shape)
fine_rows = np.arange(image_data.shape[0])

interpolator = GeoInterpolator(
    (longitude, latitude), (tie_rows, tie_cols), (fine_rows, fine_cols)
)

return interpolator.interpolate()

Problem description

I'm trying to interpolate a Tie Point Grid from a Sentinel SAR1A image but having issues with the results. The original tie grid is 10 x 21 and I'm trying to increase it to the same number of pixels as the image.

The code runs fine but visually checking the image location against the given pixel grid point gives the wrong coordinates. Is something I've doing obviously wrong?

I'd appreciate any guidance and thanks for spending time on the library.

Expected Output

Actual Result, Traceback if applicable

Versions of Python, package at hand and relevant dependencies

Thank you for reporting an issue !

Interpolator returns F-contiguous arrays

The Interpolator.interpolate method, specifically scipy's spline interpolator will return arrays that are both F-contiguous and C-contiguous. When viewing/reshaping the array the order gets set to F style, which is causing problems in satpy, since it expects the arrays be in the native, "C" order.

It appears this line is the trouble maker:

            self.new_data[num] = self.new_data[num].reshape(xpoints.shape).T

Changing it to:

            self.new_data[num] = self.new_data[num].reshape(xpoints.shape).T.copy(order='C')

Solves the problem.
The new_data arrays as returned by scipy's spline interpolator, are marked as both, C and F contiguous arrays.

>>> self.new_data[num].flags
Out:
  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False

It's probably a bug in Scipy, but enforcing the order would be a quick solution.

Move cartesian coordinate handling to a utils package

Cartesian coordinate handling could be generalized in a utils-package, something like:

from functools import wraps

def use_carts(use_carts=False, latitude_xy_threshold=60):
    """Convert input to a function to cartesian and back."""
    def decorator(func):
        @wraps(func)
        def wrapper(data, **kwargs):
            if use_carts:
                data = _lonlat2xyz(*data)
            result = func(data, **kwargs)
            if use_carts:
                result = _xyz2lonlat(*result, latitude_xy_threshold=latitude_xy_threshold)
            return result
        return wrapper
    return decorator

Usage would be simplified to

interpolate = use_carts(to_cart)(tie_points_interpolation)
return interpolate([longitude, latitude], scan_alt_tie_points, tie_points_factor)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.