MillionConcepts / pdr

[P]lanetary [D]ata [R]eader - A single function to read all Planetary Data System (PDS) data into Python
Other
62 stars 7 forks source link

import pdr doesn't work #9

Closed alemran042 closed 3 years ago

alemran042 commented 3 years ago

I have installed the pdr and "pip list" shows pdr is installed. However, when import pdr, its shows the following error:

import pdr

Traceback (most recent call last): File "", line 1, in File "/home/emran/anaconda3/lib/python3.7/site-packages/pdr/init.py", line 3, in from pdr.pdr import Data File "/home/emran/anaconda3/lib/python3.7/site-packages/pdr/pdr.py", line 264 if Path(fmtpath:= self.filename.replace( ^ SyntaxError: invalid syntax

cmillion commented 3 years ago

The walrus operator didn't exist in Python 3.7. Try it with Python 3.8+. I suggest using a conda environment to do this.

cmillion commented 3 years ago

@alemran042 Just curious if this ended up working for you.

alemran042 commented 3 years ago

@cmillion Unfortunately, it didn't end up working. I can import pdr but had another issue in reading the image. Here the code and error it shows. Also, copied the link of data (https://pds-smallbodies.astro.umd.edu/holdings/nh-p_psa-leisa_mvic-5-comp-v1.0/data/color/)

############## code ######## In [1]: import pdr

In [2]: data = pdr.read_image('mvic_0299178092_0x536_sci_pl.img')


AttributeError Traceback (most recent call last)

in ----> 1 data = pdr.read_image('mvic_0299178092_0x536_sci_pl.img') ~/SPAC/Pluto/New Horizons/copied file/Pluto Encounter Surface Composition/data/color/pdr.py in read_image(self, pointer, userasterio) 134 the use of rasterio until I can figure out how to produce consistent 135 output.""" --> 136 if (self.filename.lower().endswith('.fits') or 137 self.filename.lower().endswith('.fit')): 138 try: # Is it a FITS file? AttributeError: 'str' object has no attribute 'filename'
alemran042 commented 3 years ago

@cmillion Update I was able to read the image using a different approach. Here is how it ended up working:

In [1]: import pdr In [2]: img = pdr.rasterio.open('mvic_0299178092_0x536_sci_pl.lbl') In [3]: data = img.read() In [4]: data.shape Out[4]: (4, 4754, 4754)

Thank you, Emran

cmillion commented 3 years ago

Thanks. What made you decide to use pdr.read_image instead of pdr.read?

What happens if you try data = pdr.read('mvic_0299178092_0x536_sci_pl.img')?

Thanks.

alemran042 commented 3 years ago

@cmillion I think pdr has no module as read( ), at least in the version I am using. If I try data = pdr.read('mvic_0299178092_0x536_sci_pl.img'), it shows following error:

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' AttributeError Traceback (most recent call last)

in ----> 1 data = pdr.read('mvic_0299178092_0x536_sci_pl.lbl') AttributeError: module 'pdr' has no attribute 'read'
cmillion commented 3 years ago

Ok. That shouldn't happen. Weird. Thank you.

cmillion commented 3 years ago

Oh. When import pdr are you importing pdr.py from, like, within the git directory named pdr? Or are you importing the library pdr (like from within the directory that contains the directory named pdr)?

Or did you pip install pdr with something like pip install git+https://github.com/MillionConcepts/pdr.git?

alemran042 commented 3 years ago

@cmillion yes, I install pdr with pip install git+https://github.com/MillionConcepts/pdr.git Then, I import the library as "import pdr"

alemran042 commented 3 years ago

@cmillion ah, I got it. Unconsciously, I had the pdr.py file in the working directory. After deleting the pdr.py file, now pdr.read( ) works. Apology for the confusion. Now, it works as it is supposed to be. Thank you, Emran

cmillion commented 3 years ago

Great! Glad it's working right. Please let me know if you encounter other issues. Thank you.