SciQLop / speasy

Space Physics made EASY! A simple Python package to deal with main Space Physics WebServices (CDA,SSC,AMDA,..)
Other
24 stars 7 forks source link

PSP IS⊙IS instruments cause "invalid character" #33

Closed jgieseler closed 2 years ago

jgieseler commented 2 years ago

Description

When trying to address data of Parker Solar Probe's (PSP) particle instruments "IS⊙ISEPI_Hi" or "IS⊙ISEPI_Lo" via dynamic inventory, the special sign "⊙" causes a SyntaxError: invalid character.

What I Did

First create a clean Python 3.9 environment with conda, install latest speasy version from git via pip, and start python:

$ conda create --name speasy python=3.9
$ conda activate speasy
$ pip install git+https://github.com/SciQLop/speasy
Collecting git+https://github.com/SciQLop/speasy
  Cloning https://github.com/SciQLop/speasy to /tmp/pip-req-build-lvjo1tfp
  Running command git clone -q https://github.com/SciQLop/speasy /tmp/pip-req-build-lvjo1tfp
  Resolved https://github.com/SciQLop/speasy to commit 27b9e6c32e890c3bba5d9681459b6a3ffc7e5664
[..]
Successfully installed Click-8.0.3 PyYAML-6.0 appdirs-1.4.4 astropy-5.0.1 attrs-21.4.0 cached-property-1.5.2 charset-normalizer-2.0.11 diskcache-5.4.0 idna-3.3 isodate-0.6.1 lxml-4.7.1 numpy-1.22.1 packaging-21.3 pandas-1.4.0 platformdirs-2.4.1 pyerfa-2.0.0.1 pyparsing-3.0.7 python-dateutil-2.8.2 pytz-2021.3 requests-2.27.1 requests-file-1.5.1 requests-toolbelt-0.9.1 six-1.16.0 speasy-0.9.0 spwc-0.9.0 urllib3-1.26.8 xmltodict-0.12.0 zeep-4.1.0
$ python

Then in python:

Python 3.9.7 (default, Sep 16 2021, 13:09:58) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import speasy as spz
>>> amda_tree = spz.inventory.data_tree.amda

>>> amda_tree.Parameters.PSP.FIELDSMAG
AMDAPathIndex(name='FIELDS MAG', desc='Fluxgate magnetometer (MAG) of the FIELDS suite<br/>Magnetometer', xmlid='PSP_mag', att='auto/PSP_mag', is_public=True, psp_mag_1min=<DatasetIndex: 1min>, psp_mag_4cyc=<DatasetIndex: 4/cyc>, Venusflybys=AMDAPathIndex(xmlid='psp-venus-flybys', name='Venus flybys', is_public=True, psp_mag_vflyby1=<DatasetIndex: Venus flyby #1>, psp_mag_vflyby2=<DatasetIndex: Venus flyby #2>, psp_mag_vflyby3=<DatasetIndex: Venus flyby #3>, psp_mag_vflyby4=<DatasetIndex: Venus flyby #4>), psp_fld_qfl=<DatasetIndex: quality flag>)

>>> amda_tree.Parameters.PSP.IS⊙ISEPI_Hi
  File "<stdin>", line 1
    amda_tree.Parameters.PSP.IS⊙ISEPI_Hi
                               ^
SyntaxError: invalid character '⊙' (U+2299)

>>> amda_tree.Parameters.PSP.IS⊙ISEPI_Lo
  File "<stdin>", line 1
    amda_tree.Parameters.PSP.IS⊙ISEPI_Lo
                               ^
SyntaxError: invalid character '⊙' (U+2299)

>>> amda_tree.Parameters.PSP.IS0ISEPI_Lo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'AMDAPathIndex' object has no attribute 'IS0ISEPI_Lo'

>>> amda_tree.Parameters.PSP.ISOISEPI_Lo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'AMDAPathIndex' object has no attribute 'ISOISEPI_Lo'

>>> amda_tree.Parameters.PSP.ISoISEPI_Lo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'AMDAPathIndex' object has no attribute 'ISoISEPI_Lo'

Running amda_tree.Parameters.PSP.FIELDSMAG just to verify that it works in general. Trying to replace "⊙" with "0/O/o" doesn't solve the problem.

jeandet commented 2 years ago

@jgieseler Nice catch, this indeed come from an incomplete manual sanitizing of such names here. I didn't find a better solution at that time... I'll push a fix ASAP. The fun thing here is that you can generate invalid python names using __dict__ but there is no way to use them afterwards (except using __dict__).

jeandet commented 2 years ago

@jgieseler if you want to try the fix, you can install what will be the 0.10.0 with pip install git+https://github.com/jeandet/speasy@documentation_update_v0.10

jgieseler commented 2 years ago

Yes, that seems to work!

>>> import speasy as spz
>>> amda_tree = spz.inventory.data_tree.amda
>>> amda_tree.Parameters.PSP.ISoISEPI_Hi
AMDAPathIndex(name='IS⊙IS EPI-Hi', desc='Energetic Particle Instrument Hi-Energy<br/>SolidStateDetector', xmlid='PSP_epihi', att='auto/PSP_epihi', is_public=True, HET=AMDAPathIndex(xmlid='psp-isois-het', name='HET', is_public=True, psp_het_1hr=<DatasetIndex: HET 1h>, psp_het_1min=<DatasetIndex: HET 1min>), LET1=AMDAPathIndex(xmlid='psp-isois-let1', name='LET1', is_public=True, psp_let1_1hr=<DatasetIndex: LET1 1h>, psp_let1_1min=<DatasetIndex: LET1 1min>), LET2=AMDAPathIndex(xmlid='psp-isois-let2', name='LET2', is_public=True, psp_let2_1hr=<DatasetIndex: LET2 1h>, psp_let2_1min=<DatasetIndex: LET2 1min>))

And I think it's not really a problem; I've seen it written with an "o" already somewhere else. Even the instrument team has to use this workaround for its URL: https://spp-isois.sr.unh.edu 😉