Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
teutoburg committed Oct 23, 2023
1 parent 9d83b7d commit 8a7c6a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
39 changes: 19 additions & 20 deletions skycalc_ipy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def get_cache_filenames(params: Dict, prefix: str, suffix: str):
2. As set in the `scopesim_data` package.
3. The `data` directory in this package.
"""

if "SKYCALC_IPY_CACHE_DIR" in environ:
dir_cache = Path(environ["SKYCALC_IPY_CACHE_DIR"])
elif isinstance(scopesim_data, ModuleType):
Expand All @@ -55,7 +54,7 @@ def get_cache_filenames(params: Dict, prefix: str, suffix: str):

class AlmanacQuery:
"""
A class for querying the SkyCalc Almanac
A class for querying the SkyCalc Almanac.
Parameters
----------
Expand Down Expand Up @@ -156,15 +155,16 @@ def __init__(self, indic):

def query(self):
"""
Queries the ESO Skycalc server with the parameters in self.almindic
Query the ESO Skycalc server with the parameters in self.almindic.
Returns
-------
almdata : dict
Dictionary with the relevant parameters for the date given
"""
fn_data, fn_params = get_cache_filenames(self.almindic, "almanacquery", "json")
fn_data, fn_params = get_cache_filenames(self.almindic,
"almanacquery", "json")
if fn_data.exists():
jsondata = json.load(open(fn_data))
else:
Expand Down Expand Up @@ -209,7 +209,7 @@ def query(self):

class SkyModel:
"""
Class for querying the Advanced SkyModel at ESO
Class for querying the Advanced SkyModel at ESO.
Contains all the parameters needed for querying the ESO SkyCalc server.
The parameters are contained in :attr:`.params` and the returned FITS file
Expand Down Expand Up @@ -320,13 +320,12 @@ def __init__(self):

def fix_observatory(self):
"""
Converts the human readable observatory name into its ESO ID number
Convert the human readable observatory name into its ESO ID number.
The following observatory names are accepted: ``lasilla``, ``paranal``,
``armazones`` or ``3060m``, ``highanddry`` or ``5000m``
"""

if self.params["observatory"] == "lasilla":
self.params["observatory"] = "2400"
elif self.params["observatory"] == "paranal":
Expand Down Expand Up @@ -354,7 +353,7 @@ def __setitem__(self, key, value):
if key == "observatory":
self.fix_observatory()

def handle_exception(self, err, msg):
def _handle_exception(self, err, msg):
print(msg)
print(err)
print(self.bugreport_text)
Expand All @@ -364,15 +363,15 @@ def handle_exception(self, err, msg):
# tool or something like that. However, skycalc_ipy is also used as
# a library, and libraries should never just exit and this
# command-line functionality does not seem to exist. So instead,
# just raise here. See also handle_error() below.
# just raise here. See also _handle_error() below.
raise

# handle the kind of errors we issue ourselves.
def handle_error(self, msg):
def _handle_error(self, msg):
print(msg)
print(self.bugreport_text)
if self.stop_on_errors_and_exceptions:
# See handle_exception above.
# See _handle_exception above.
raise

def retrieve_data(self, url):
Expand All @@ -382,15 +381,15 @@ def retrieve_data(self, url):
# identical requests.
self.data[0].header["DATE"] = "2017-01-07T00:00:00"
except requests.exceptions.RequestException as err:
self.handle_exception(
self._handle_exception(
err, "Exception raised trying to get FITS data from " + url
)

def write(self, local_filename, **kwargs):
try:
self.data.writeto(local_filename, **kwargs)
except (IOError, FileNotFoundError) as err:
self.handle_exception(err, "Exception raised trying to write fits file ")
self._handle_exception(err, "Exception raised trying to write fits file ")

def getdata(self):
return self.data
Expand All @@ -402,9 +401,9 @@ def delete_server_tmpdir(self, tmpdir):
)
deleter_response = response.text.strip()
if deleter_response != "ok":
self.handle_error("Could not delete server tmpdir " + tmpdir)
self._handle_error("Could not delete server tmpdir " + tmpdir)
except requests.exceptions.RequestException as err:
self.handle_exception(
self._handle_exception(
err, "Exception raised trying to delete tmp dir " + tmpdir
)

Expand All @@ -428,7 +427,7 @@ def call(self, test=False):
self.url, data=json.dumps(self.params), timeout=self.REQUEST_TIMEOUT
)
except requests.exceptions.RequestException as err:
self.handle_exception(
self._handle_exception(
err, "Exception raised trying to POST request " + self.url
)
return
Expand All @@ -438,7 +437,7 @@ def call(self, test=False):
status = res["status"]
tmpdir = res["tmpdir"]
except (KeyError, ValueError) as err:
self.handle_exception(
self._handle_exception(
err, "Exception raised trying to decode server response "
)
return
Expand All @@ -450,7 +449,7 @@ def call(self, test=False):
# retrive and save FITS data (in memory)
self.retrieve_data(tmpurl)
except requests.exceptions.RequestException as err:
self.handle_exception(err, "could not retrieve FITS data from server")
self._handle_exception(err, "could not retrieve FITS data from server")

try:
self.data.writeto(fn_data)
Expand All @@ -462,7 +461,7 @@ def call(self, test=False):
self.delete_server_tmpdir(tmpdir)

else: # print why validation failed
self.handle_error("parameter validation error: " + res["error"])
self._handle_error("parameter validation error: " + res["error"])

if test:
# print 'call() returning status:',status
Expand All @@ -478,7 +477,7 @@ def callwith(self, newparams):

def printparams(self, keys=None):
"""
List the values of all, or a subset, of parameters
List the values of all, or a subset, of parameters.
Parameters
----------
Expand Down
3 changes: 1 addition & 2 deletions skycalc_ipy/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_almanac_data(

def get_sky_spectrum(self, return_type="table", filename=None):
"""
Retrieve a fits.HDUList object from the SkyCalc server
Retrieve a fits.HDUList object from the SkyCalc server.
The HDUList can be returned in a variety of formats.
Expand All @@ -138,7 +138,6 @@ def get_sky_spectrum(self, return_type="table", filename=None):
- "fits": hdu (HDUList)
"""

from astropy import table

if not self.validate_params():
Expand Down

0 comments on commit 8a7c6a1

Please sign in to comment.