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

Make it work on recent Python #53

Merged
merged 25 commits into from
Mar 19, 2024
Merged

Make it work on recent Python #53

merged 25 commits into from
Mar 19, 2024

Conversation

matteobachetti
Copy link
Contributor

@matteobachetti matteobachetti commented Mar 18, 2024

I arrived up to installing (now with pip install .) and running runbasie out -c configuration_SR.txt -d.
Feel free to suggest any further tests you would like to run to make sure it works!

User-facing changes:

To run tests, you can now do
pytest basie/tests
or
tox -e py{38,39,310,311,312}-tests to test locally on any of those Python versions

Internal changes:
I moved around directories, eliminating soft links and giving the package a standard astropy-affiliated package structure. It seems like I changed a thousand things, but the diff is mostly the result of changing directory names.
I think it is now easier to follow where things actually are. The script runbasie is automatically generated during installation, the version is automatically tracked from the git tags.

@matteobachetti matteobachetti marked this pull request as draft March 18, 2024 14:43
@matteobachetti matteobachetti changed the title Make it work on Py311 Make it work on Python 3.11 Mar 18, 2024
@sergiopoppi
Copy link
Member

Traceback (most recent call last): File "/home/spoppi/anaconda3/envs/basie3.11/bin/runbasie", line 5, in <module> from basie import cmd_line ModuleNotFoundError: No module named 'basie'

Not working

@matteobachetti
Copy link
Contributor Author

@sergiopoppi how did you install it? pip install .?

@sergiopoppi
Copy link
Member

@sergiopoppi how did you install it? pip install .?

A clean shell improved... Runbasie now works.

Other problems:

runbasie
INFO: generating schedule from user input file: configuration.txt
INFO: exiting with error
ERROR: module 'collections' has no attribute 'Mapping'

@matteobachetti

This comment was marked as resolved.

@matteobachetti matteobachetti changed the title Make it work on Python 3.11 Make it work on recent Python Mar 18, 2024
@matteobachetti
Copy link
Contributor Author

matteobachetti commented Mar 18, 2024

Current status:

  1. I got Basie to run correctly the following command:
$ runbasie out -c configuration_SR.txt
INFO: generating schedule from user input file: configuration_SR.txt
validating TP{'type': 'TOTALPOWER', 'integration': '10', 'samplingInterval': '10.0', 'bandwidth': '300'}
Configurazione:+{'integration': '10', 'samplingInterval': '10.0', 'bandwidth': '300', 'name': 'TP'}
In init2
validating TP20_730{'type': 'TOTALPOWER', 'integration': '20', 'samplingInterval': '20.0', 'bandwidth': '730'}
Configurazione:+{'integration': '20', 'samplingInterval': '20.0', 'bandwidth': '730', 'name': 'TP20_730'}
In init2
validating TP40_1250{'type': 'TOTALPOWER', 'integration': '40', 'samplingInterval': '40.0', 'bandwidth': '1250', 'feeds': '3;6'}
Configurazione:+{'integration': '40', 'samplingInterval': '40.0', 'bandwidth': '1250', 'feeds': '3;6', 'name': 'TP40_1250'}
In init2
validating XK77{'type': 'XARCOS', 'configuration': 'XK77', 'feeds': '0;7'}
Configurazione:+{'configuration': 'XK77', 'feeds': '0;7', 'name': 'XK77'}
validating XC00{'type': 'XARCOS', 'configuration': 'skip'}
Configurazione:+{'configuration': 'skip', 'name': 'XC00'}
validating SARDARA{'type': 'Sardara', 'feeds': '0;7'}
Configurazione:+{'feeds': '0;7', 'name': 'SARDARA'}
backend validated
INFO: exploding scanmode EQMap1x1 in 2 separate scans: EQMap1x1_lon and EQMap1x1_lat
INFO: exploding scanmode EQMap1x1S in 2 separate scans: EQMap1x1S_lon and EQMap1x1S_lat
INFO: Scheduling SRT radiotelescope using receiver KM
INFO: writing Nodding36 on Gamma
Feed_a 3 Feed_b6
Derotator: 0
Derotator: 0
HOR lon: -0.0382d lat: 0.0000d
HOR lon: 0.0382d lat: 0.0000d
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
INFO: closing gently

When running tests, I found that they were a little unmaintained. For example, some tests were requiring old versions of configuration test files. I copied an old test file to verify everything worked, and I now only have these two failures, which I frankly don't know how to address.

$ pytest basie/tests/ -svv
======================================= test session starts ========================================
platform darwin -- Python 3.12.2, pytest-8.1.1, pluggy-1.4.0 -- /Users/meo/opt/anaconda3/envs/clean12/bin/python
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase(PosixPath('/Users/meo/devel/basie/.hypothesis/examples'))

Running tests with basie version 1.1.dev31+gda01dec.d20240318.
Running tests in basie/tests/.

Date: 2024-03-19T00:39:53

Platform: macOS-14.4-arm64-arm-64bit

Executable: /Users/meo/opt/anaconda3/envs/clean12/bin/python

Full Python Version: 
3.12.2 | packaged by Anaconda, Inc. | (main, Feb 27 2024, 12:57:28) [Clang 14.0.6 ]

encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8
byteorder: little
float info: dig: 15, mant_dig: 15

Package versions: 
Numpy: 1.26.4
Scipy: not available
Matplotlib: not available
h5py: not available
scikit-image: not available

Using Astropy options: remote_data: none.

rootdir: /Users/meo/devel/basie
configfile: setup.cfg
plugins: astropy-0.11.0, hypothesis-6.99.8, remotedata-0.4.1, cov-4.1.0, filter-subpackage-0.2.0, doctestplus-1.2.1, astropy-header-0.2.2, mock-3.12.0, arraydiff-0.6.1
collected 56 items                                                                                 

basie/tests/test_backend.py::TestRoachBackend::test_roach_backend_bck_file PASSED
basie/tests/test_backend.py::TestRoachBackend::test_roach_backend_instructions PASSED
basie/tests/test_backend.py::TestTotalPowerBackend::test_set_addition PASSED
basie/tests/test_backend.py::TestTotalPowerBackend::test_total_power_set_sections PASSED
basie/tests/test_backend.py::TestTotalPowerBackend::test_total_power_set_sections_enable [(0, 300.0), (1, 300.0)]
FAILED
basie/tests/test_frame.py::TestFrame::test_equality PASSED
basie/tests/test_frame.py::TestCoord::test_constructor PASSED
basie/tests/test_frame.py::TestCoord::test_copy PASSED
basie/tests/test_frame.py::TestCoord::test_equality PASSED
basie/tests/test_frame.py::TestCoord::test_sum PASSED
basie/tests/test_installation.py::TestInstallation::test_astropy_version PASSED
basie/tests/test_installation.py::TestInstallation::test_version PASSED
basie/tests/test_maps.py::TestMapScan::test_multi_feed_dynamic_spacing PASSED
basie/tests/test_maps.py::TestMapScan::test_multi_feed_fixed_spacing PASSED
basie/tests/test_maps.py::TestMapScan::test_single_feed_dynamic_spacing PASSED
basie/tests/test_maps.py::TestMapScan::test_single_feed_fixed_spacing PASSED
basie/tests/test_nodding.py::TestNoddingScan::test_nodding Feed_a 3 Feed_b0
FAILED
basie/tests/test_procedures.py::TestProcedures::test_one_param_procedure_definition PASSED
basie/tests/test_procedures.py::TestProcedures::test_one_param_procedure_execution PASSED
basie/tests/test_procedures.py::TestProcedures::test_simple_procedure_definition PASSED
basie/tests/test_procedures.py::TestProcedures::test_simple_procedure_sum PASSED
basie/tests/test_procedures.py::TestProcedures::test_sum_simple_one_param_definition PASSED
basie/tests/test_procedures.py::TestProcedures::test_sum_simple_one_param_execution PASSED
basie/tests/test_receivers.py::TestReceiver::test_get_beamsize PASSED
basie/tests/test_receivers.py::TestReceiver::test_valid_pairs Derotator: -30
HOR lon: -0.0331d lat: 0.0191d
Derotator: -30
HOR lon: 0.0331d lat: 0.0191d
PROC_DEROTATORFIXED_300{
        derotatorSetConfiguration=FIXED
        derotatorSetPosition=30.0d
}

PASSED
basie/tests/test_rich_validator.py::TestRichValidator::test_check_frame PASSED
basie/tests/test_rich_validator.py::TestRichValidator::test_string2list PASSED
basie/tests/test_schedule.py::TestSchedule::test_schedule_files_do_not_contain_whitespaces validating TP{'type': 'TOTALPOWER', 'integration': '10', 'samplingInterval': '10.0', 'bandwidth': '300'}
Configurazione:+{'integration': '10', 'samplingInterval': '10.0', 'bandwidth': '300', 'name': 'TP'}
validating TP20_730{'type': 'TOTALPOWER', 'integration': '20', 'samplingInterval': '20.0', 'bandwidth': '730'}
Configurazione:+{'integration': '20', 'samplingInterval': '20.0', 'bandwidth': '730', 'name': 'TP20_730'}
validating TP40_1250{'type': 'TOTALPOWER', 'integration': '40', 'samplingInterval': '40.0', 'bandwidth': '1250', 'feeds': '3;6'}
Configurazione:+{'integration': '40', 'samplingInterval': '40.0', 'bandwidth': '1250', 'feeds': '3;6', 'name': 'TP40_1250'}
validating XK77{'type': 'XARCOS', 'configuration': 'XK77', 'feeds': '0;7'}
Configurazione:+{'configuration': 'XK77', 'feeds': '0;7', 'name': 'XK77'}
validating XC00{'type': 'XARCOS', 'configuration': 'skip'}
Configurazione:+{'configuration': 'skip', 'name': 'XC00'}
validating SARDARA{'type': 'Sardara', 'feeds': '0;7'}
Configurazione:+{'feeds': '0;7', 'name': 'SARDARA'}
backend validated
Feed_a 3 Feed_b6
Derotator: 0
Derotator: 0
HOR lon: -0.0382d lat: 0.0000d
HOR lon: 0.0382d lat: 0.0000d
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
PASSED
basie/tests/test_schedule.py::TestSchedule::test_schedule_parameters validating TP{'type': 'TOTALPOWER', 'integration': '10', 'samplingInterval': '10.0', 'bandwidth': '300'}
Configurazione:+{'integration': '10', 'samplingInterval': '10.0', 'bandwidth': '300', 'name': 'TP'}
validating TP20_730{'type': 'TOTALPOWER', 'integration': '20', 'samplingInterval': '20.0', 'bandwidth': '730'}
Configurazione:+{'integration': '20', 'samplingInterval': '20.0', 'bandwidth': '730', 'name': 'TP20_730'}
validating TP40_1250{'type': 'TOTALPOWER', 'integration': '40', 'samplingInterval': '40.0', 'bandwidth': '1250', 'feeds': '3;6'}
Configurazione:+{'integration': '40', 'samplingInterval': '40.0', 'bandwidth': '1250', 'feeds': '3;6', 'name': 'TP40_1250'}
validating XK77{'type': 'XARCOS', 'configuration': 'XK77', 'feeds': '0;7'}
Configurazione:+{'configuration': 'XK77', 'feeds': '0;7', 'name': 'XK77'}
validating XC00{'type': 'XARCOS', 'configuration': 'skip'}
Configurazione:+{'configuration': 'skip', 'name': 'XC00'}
validating SARDARA{'type': 'Sardara', 'feeds': '0;7'}
Configurazione:+{'feeds': '0;7', 'name': 'SARDARA'}
backend validated
PASSED
basie/tests/test_schedule.py::TestSchedule::test_write_schedule_files validating TP{'type': 'TOTALPOWER', 'integration': '10', 'samplingInterval': '10.0', 'bandwidth': '300'}
Configurazione:+{'integration': '10', 'samplingInterval': '10.0', 'bandwidth': '300', 'name': 'TP'}
validating TP20_730{'type': 'TOTALPOWER', 'integration': '20', 'samplingInterval': '20.0', 'bandwidth': '730'}
Configurazione:+{'integration': '20', 'samplingInterval': '20.0', 'bandwidth': '730', 'name': 'TP20_730'}
validating TP40_1250{'type': 'TOTALPOWER', 'integration': '40', 'samplingInterval': '40.0', 'bandwidth': '1250', 'feeds': '3;6'}
Configurazione:+{'integration': '40', 'samplingInterval': '40.0', 'bandwidth': '1250', 'feeds': '3;6', 'name': 'TP40_1250'}
validating XK77{'type': 'XARCOS', 'configuration': 'XK77', 'feeds': '0;7'}
Configurazione:+{'configuration': 'XK77', 'feeds': '0;7', 'name': 'XK77'}
validating XC00{'type': 'XARCOS', 'configuration': 'skip'}
Configurazione:+{'configuration': 'skip', 'name': 'XC00'}
validating SARDARA{'type': 'Sardara', 'feeds': '0;7'}
Configurazione:+{'feeds': '0;7', 'name': 'SARDARA'}
backend validated
Feed_a 3 Feed_b6
Derotator: 0
Derotator: 0
HOR lon: -0.0382d lat: 0.0000d
HOR lon: 0.0382d lat: 0.0000d
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
Receiver:KM
PASSED
basie/tests/test_subscan.py::TestSubscan::test_get_cen_otf PASSED
basie/tests/test_subscan.py::TestSubscan::test_get_tsys PASSED
basie/tests/test_target.py::TestTarget::test_parse_file PASSED
basie/tests/test_target.py::TestTarget::test_parse_file_negative_coord PASSED
basie/tests/test_target.py::TestTarget::test_parse_line PASSED
basie/tests/test_utils.py::TestUtils::test_ceil_to_odd PASSED
basie/tests/test_utils.py::TestUtils::test_ceil_to_odd_valid_angle PASSED
basie/tests/test_utils.py::TestUtils::test_extrude_from_rectangle PASSED
basie/tests/test_valid_angles.py::TestAngles::test_creation PASSED
basie/tests/test_valid_angles.py::TestAngles::test_fmt_dec PASSED
basie/tests/test_valid_angles.py::TestAngles::test_fmt_dec_neg PASSED
basie/tests/test_valid_angles.py::TestAngles::test_fmt_dms PASSED
basie/tests/test_valid_angles.py::TestAngles::test_fmt_hms PASSED
basie/tests/test_valid_angles.py::TestAngles::test_parsing PASSED
basie/tests/test_valid_angles.py::TestAngles::test_parsing_dec PASSED
basie/tests/test_valid_angles.py::TestAngles::test_parsing_deg PASSED
basie/tests/test_valid_angles.py::TestAngles::test_parsing_hour PASSED
basie/tests/test_valid_angles.py::TestAngles::test_sum PASSED
basie/tests/test_valid_angles.py::TestAngles::test_sum_dec_hms PASSED
basie/tests/test_valid_angles.py::TestAngles::test_sum_is_vangle PASSED
basie/tests/test_valid_angles.py::TestAngles::test_sum_keeps_attributes PASSED
basie/tests/test_valid_angles.py::TestAngles::test_vangle_is_hour_angle PASSED
basie/tests/test_valid_angles.py::TestAngles::test_vangle_is_not_hour_angle PASSED
basie/tests/test_validator.py::TestValidator::test_check_frame PASSED
basie/tests/test_validator.py::TestValidator::test_string2list PASSED
basie/tests/test_validator.py::TestValidator::test_validate_configuration validating TP{'type': 'TOTALPOWER', 'integration': '10', 'samplingInterval': '10.0', 'bandwidth': '300'}
Configurazione:+{'integration': '10', 'samplingInterval': '10.0', 'bandwidth': '300', 'name': 'TP'}
validating TP20_730{'type': 'TOTALPOWER', 'integration': '20', 'samplingInterval': '20.0', 'bandwidth': '730'}
Configurazione:+{'integration': '20', 'samplingInterval': '20.0', 'bandwidth': '730', 'name': 'TP20_730'}
validating XK77{'type': 'XARCOS', 'configuration': 'XK77'}
Configurazione:+{'configuration': 'XK77', 'name': 'XK77'}
validating XC00{'type': 'XARCOS', 'configuration': 'skip'}
Configurazione:+{'configuration': 'skip', 'name': 'XC00'}
validating SARDARA{'type': 'Sardara'}
Configurazione:+{'name': 'SARDARA'}
backend validated
PASSED

============================================= FAILURES =============================================
____________________ TestTotalPowerBackend.test_total_power_set_sections_enable ____________________

self = <basie.tests.test_backend.TestTotalPowerBackend testMethod=test_total_power_set_sections_enable>

    def test_total_power_set_sections_enable(self):
        self.backend.set_sections(2)
        instructions = StringIO(str(self.backend._get_backend_instructions()))
        lines = instructions.readlines()
        enable_line = lines[-1].strip()
>       self.assertTrue(enable_line.startswith("enable"))
E       AssertionError: False is not true

basie/tests/test_backend.py:44: AssertionError
___________________________________ TestNoddingScan.test_nodding ___________________________________

self = <basie.tests.test_nodding.TestNoddingScan testMethod=test_nodding>

    def test_nodding(self):
>      self._nodding._do_scan(self.TARGET,self._recv,20.000)

basie/tests/test_nodding.py:32: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
basie/scanmode/nodding.py:33: in _do_scan
    offset_a = _receiver.get_feed_offset(self.feed_a,(self.feed_a,self.feed_b))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <basie.receiver.Receiver object at 0x11e8be510>, feed_number = 3, feed_pair = (3, 0)
frame = <basie.frame.Frame object at 0x10f7fce30>

    def get_feed_offset(self, feed_number, feed_pair, frame=HOR):
        derotator_angle = 0.0
        valid_pair = False
        if self.nfeed < 2:
            raise ReceiverError("Cannot get offset for single feed recevier.")
    
        if self.feeds_valid_pairs is None:
>           raise ReceiverError("Feed table not properly setted. None is found.")
E           basie.errors.ReceiverError: Feed table not properly setted. None is found.

basie/receiver.py:150: ReceiverError
===================================== short test summary info ======================================
FAILED basie/tests/test_backend.py::TestTotalPowerBackend::test_total_power_set_sections_enable - AssertionError: False is not true
FAILED basie/tests/test_nodding.py::TestNoddingScan::test_nodding - basie.errors.ReceiverError: Feed table not properly setted. None is found.
=================================== 2 failed, 54 passed in 0.42s ===================================

@matteobachetti matteobachetti marked this pull request as ready for review March 19, 2024 12:25
@matteobachetti
Copy link
Contributor Author

Just for the sake of understanding if always the same two tests don't pass, I marked them as xfail, which means they are, at the moment, expected not to pass.
Now it is clear that tests pass in all architectures and dependency configurations but the development versions of astropy/numpy etc, for reasons that seem internal to Astropy though.

Read from beamsize_table the nearest frequency value.
If freq is None defauls to self.fmin
@param freq: frequency (MHz)
@type freq: Quantity
@return: beamsize at given frequency
"""
if not freq:
if freq is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This did not work anymore when freq was a quantity, so I explicitly used the test for None.

@@ -10,13 +10,16 @@
from basie import target_parser

BASE_PATH = ".basie_test"
curdir = os.path.abspath(os.path.dirname(__file__))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed all paths to data files to be relative to the current directory but without needing soft links (which would not work on Windows, by the way)

@@ -0,0 +1,10 @@
Alpha EqCross1_3 TP EQ 12:00:00h +45:00:00
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this file reproducing the test cases that were needed for some tests but were removed in some recent version of the example files.

@@ -43,9 +43,15 @@

class VAngle(Angle):
def __new__(cls, angle, unit=u.deg, wrap_angle=360 * u.deg, **kwargs):
was_tuple=False
if isinstance(angle, tuple) and unit in (u.deg, u.hour):
Copy link
Contributor Author

@matteobachetti matteobachetti Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tuple of values does not work anymore with astropy's Angle in recent versions, due to its ambiguous behavior when the degree/hour value is 0. So, I reformatted the angle as a single number in degrees when it is given as a tuple, but kept the representation as sexagesimal so that the output does not change.

@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@sergiopoppi sergiopoppi merged commit 841dc4a into master Mar 19, 2024
6 of 7 checks passed
@sergiopoppi sergiopoppi deleted the make_it_work_on_py_311 branch March 19, 2024 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants