astroplan icon indicating copy to clipboard operation
astroplan copied to clipboard

Astroplan - set issue

Open dsliski opened this issue 1 year ago • 2 comments

Hi,

I am trying to use the astroplan feature to decide when to observe various fields for an all sky H-alpha Survey. I am trying to incorporate the "best_month" feature into my output table which will then be used to decide which fields to schedule when. However, some of the fields are not observable due to only being observable from the Northern Hemisphere or Southern Hemisphere. As a result, I think best months should return an empty list. However, when it tries to write the column to a text file, it throws an error

"TypeError: unhashable type: 'set'"

Happy to share my python notebook if that is helpful. Just can't upload it here.

Best,

David

dsliski avatar Jul 19 '24 16:07 dsliski

Thanks for reposting, @dsliski !

Notebook available from https://groups.google.com/g/astropy-dev/c/UmQdDbRgbS0 -- FYI

pllim avatar Jul 19 '24 17:07 pllim

Hi @dsliski!

For context here on GitHub, the code that @dsliski is trying to run looks like this:

from astropy.table import Table

observability_table = Table()

observability_table['targets'] = ['a', 'b', 'c']
observability_table['ever_observable'] = [True, True, False]
observability_table['always_observable'] = [True, False, False]
observability_table['best_months'] = [set([1, 2, 3]), set([2, 3]), set()]

observability_table.write('example_table.csv', overwrite=True)

The best_months column is a list of sets. Each element of an astropy Table object is supposed to be a hashable type – it shouldn't be a list, set, array, etc. You can get the behavior you're looking for by converting each set into a string like this, for example:

from astropy.table import Table

observability_table = Table()

observability_table['targets'] = ['a', 'b', 'c']
observability_table['ever_observable'] = [True, True, False]
observability_table['always_observable'] = [True, False, False]
observability_table['best_months'] = [set([1, 2, 3]), set([2, 3]), set()]

# convert sets to strings:
observability_table['best_months'] = [str(months) for months in observability_table['best_months']]

observability_table.write('example_table.csv', overwrite=True)

The resulting csv file looks like this:

targets,ever_observable,always_observable,best_months
a,True,True,"{1, 2, 3}"
b,True,False,"{2, 3}"
c,False,False,set()

Depending on what you plan to do with this table, you may want to store your results differently.

Does that answer your question?

bmorris3 avatar Jul 19 '24 19:07 bmorris3