Skip to content

Commit

Permalink
Merge pull request DarkEnergySurvey#91 from DarkEnergySurvey/lint2
Browse files Browse the repository at this point in the history
Cleaning up lint
  • Loading branch information
kadrlica authored Jul 15, 2021
2 parents 00810f8 + d9859aa commit 07a93b0
Show file tree
Hide file tree
Showing 34 changed files with 170 additions and 510 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ name: build

on:
push:
branches: [ master, actions ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 0 1 * *'

jobs:
build:
Expand Down Expand Up @@ -38,19 +38,17 @@ jobs:
source activate env
export UGALIDIR="$HOME/.ugali"
python setup.py -q install --isochrones --catalogs
- name: Install test data
run: |
wget https://github.com/DarkEnergySurvey/ugali/releases/download/v1.7.0/ugali-test-data.tar.gz -O ugali-test-data.tar.gz
tar -xzf ugali-test-data.tar.gz
- name: Lint with flake8
if: ${{ false }}
if: ${{ true }}
run: |
source activate env
conda install -q flake8 -c conda-forge
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Install test data
run: |
wget https://github.com/DarkEnergySurvey/ugali/releases/download/v1.7.0/ugali-test-data.tar.gz -O ugali-test-data.tar.gz
tar -xzf ugali-test-data.tar.gz
- name: Test with nose
run: |
source activate env
Expand Down
5 changes: 5 additions & 0 deletions ugali/analysis/prior.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/usr/bin/env python
"""
Incomplete module for dealing with priors...
"""

import scipy.stats

class Prior(object):
def __call__(self, value):
Expand Down
3 changes: 2 additions & 1 deletion ugali/analysis/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import ugali.utils.stats
from ugali.utils.stats import Samples
from ugali.utils.projector import dist2mod,mod2dist,gal2cel,gal2cel_angle
from ugali.utils.projector import dist2mod,mod2dist
from ugali.utils.projector import cel2gal,gal2cel,gal2cel_angle
from ugali.utils.projector import ang2const, ang2iau
from ugali.utils.config import Config
from ugali.utils.logger import logger
Expand Down
11 changes: 7 additions & 4 deletions ugali/analysis/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ def search(self, coords=None, distance_modulus=None, extension=None, tolerance=1
self.stellar_mass_array = np.zeros([nmoduli,npixels],dtype='f4')
self.fraction_observable_array = np.zeros([nmoduli,npixels],dtype='f4')
self.extension_fit_array = np.zeros([nmoduli,npixels],dtype='f4')
# DEPRECATED: ADW 2019-04-27
self.richness_lower_array = np.zeros([nmoduli,npixels],dtype='f4')
self.richness_upper_array = np.zeros([nmoduli,npixels],dtype='f4')
self.richness_ulimit_array = np.zeros([nmoduli,npixels],dtype='f4')
if self.config['scan']['full_pdf']:
# DEPRECATED: ADW 2019-04-27
DeprecationWarning("'full_pdf' is deprecated.")
self.richness_lower_array = np.zeros([nmoduli,npixels],dtype='f4')
self.richness_upper_array = np.zeros([nmoduli,npixels],dtype='f4')
self.richness_ulimit_array = np.zeros([nmoduli,npixels],dtype='f4')

# Specific pixel/distance_modulus
coord_idx, distance_modulus_idx, extension_idx = None, None, None
Expand Down Expand Up @@ -315,6 +317,7 @@ def write(self, outfile):
data['PIXEL']=self.roi.pixels_target
# Full data output (too large for survey)
if self.config['scan']['full_pdf']:
DeprecationWarning("'full_pdf' is deprecated.")
data['LOG_LIKELIHOOD']=self.loglike_array.T
data['RICHNESS']=self.richness_array.T
data['RICHNESS_LOWER']=self.richness_lower_array.T
Expand Down
4 changes: 2 additions & 2 deletions ugali/candidate/associate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
# glon, glat = ugali.utils.projector.celToGal(lon,lat)
# else:
# glon,glat = lon, lat
# return ugali.utils.projector.match(glon,glat,self.data['glon'],self.data['glat'],tol)
# return ugali.utils.projector.match(glon,glat,self['glon'],self['glat'],tol)



Expand Down Expand Up @@ -452,7 +452,7 @@ def catalogFactory(name, **kwargs):
catalogs = odict(inspect.getmembers(sys.modules[__name__], fn))

if name not in list(catalogs.keys()):
msg = "%s not found in catalogs:\n %s"%(name,list(kernels.keys()))
msg = "%s not found in catalogs:\n %s"%(name,list(catalogs.keys()))
logger.error(msg)
msg = "Unrecognized catalog: %s"%name
raise Exception(msg)
Expand Down
2 changes: 1 addition & 1 deletion ugali/isochrone/dartmouth.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _parse(self,filename):
try:
columns = self.columns[self.survey.lower()]
except KeyError as e:
logger.warning('Unrecognized survey: %s'%(survey))
logger.warning('Unrecognized survey: %s'%(self.survey))
raise(e)

kwargs = dict(comments='#',usecols=list(columns.keys()),dtype=list(columns.values()))
Expand Down
3 changes: 3 additions & 0 deletions ugali/isochrone/empirical.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
Generic python script.
"""
import os
from collections import OrderedDict as odict

from ugali.analysis.model import Model, Parameter
from ugali.utils.shell import mkdir, get_ugali_dir, get_iso_dir
from ugali.isochrone.parsec import PadovaIsochrone

class EmpiricalPadova(PadovaIsochrone):
Expand Down
2 changes: 1 addition & 1 deletion ugali/isochrone/mesa.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _parse(self,filename):
try:
columns = self.columns[self.survey.lower()]
except KeyError as e:
logger.warning('Unrecognized survey: %s'%(survey))
logger.warning('Unrecognized survey: %s'%(self.survey))
raise(e)

kwargs = dict(comments='#',usecols=list(columns.keys()),dtype=list(columns.values()))
Expand Down
22 changes: 0 additions & 22 deletions ugali/isochrone/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,27 +322,6 @@ def stellar_luminosity(self, steps=10000):

return np.sum(luminosity * d_log_mass * self.imf.pdf(mass, log_mode=True))

def stellar_luminosity2(self, steps=10000):
"""
DEPRECATED: ADW 2017-09-20
Compute the stellar luminosity (L_Sol; average per star).
Uses "sample" to generate mass sample and pdf. The range of
integration only covers the input isochrone data (no
extrapolation used), but this seems like a sub-percent effect
if the isochrone goes to 0.15 Msun for the old and metal-poor
stellar populations of interest.
Note that the stellar luminosity is very sensitive to the
post-AGB population.
"""
msg = "'%s.stellar_luminosity2': ADW 2017-09-20"%self.__class__.__name__
DeprecationWarning(msg)
mass_init, mass_pdf, mass_act, mag_1, mag_2 = self.sample(mass_steps=steps)
luminosity_interpolation = scipy.interpolate.interp1d(self.mass_init, self.luminosity,fill_value=0,bounds_error=False)
luminosity = luminosity_interpolation(mass_init)
return np.sum(luminosity * mass_pdf)

# ADW: For temporary backward compatibility
stellarMass = stellar_mass
stellarLuminosity = stellar_luminosity
Expand All @@ -354,7 +333,6 @@ def absolute_magnitude(self, richness=1, steps=1e4):
g,r -> V transform equations from Jester 2005
[astro-ph/0506022].
TODO: ADW If richness not specified, should use self.richness
Parameters:
Expand Down
17 changes: 15 additions & 2 deletions ugali/isochrone/padova.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
#!/usr/bin/env python
"""
Older (pre-PARSEC) Padova isochrones.
Not verified to work...
"""
import os.path
from collections import OrderedDict as odict

import numpy as np

from ugali.analysis.model import Model, Parameter
from ugali.utils.shell import mkdir, get_ugali_dir, get_iso_dir
from ugali.isochrone.model import Isochrone
from ugali.isochrone.parsec import Marigo2017 as Padova
from ugali.isochrone.parsec import defaults_27
from ugali.utils.logger import logger

class Girardi2002(Padova):
defaults = dict(defaults_27)
Expand All @@ -19,7 +32,7 @@ class Girardi2010b(Padova):
defaults = dict(defaults_27)
defaults['isoc_kind'] = 'gi10b'

class Girardi2002(PadovaIsochrone):
class Girardi2002(Padova):
#_dirname = '/u/ki/kadrlica/des/isochrones/v5/'
_dirname = os.path.join(get_iso_dir(),'{survey}','girardi2002')
# For use with Marigo et al. (2008) and earlier use Anders & Grevesse 1989
Expand Down Expand Up @@ -57,7 +70,7 @@ def _parse(self,filename):
try:
columns = self.columns[self.survey.lower()]
except KeyError as e:
logger.warning('did not recognize survey %s'%(survey))
logger.warning('did not recognize survey %s'%(self.survey))
raise(e)

kwargs = dict(delimiter='\t',usecols=list(columns.keys()),dtype=list(columns.values()))
Expand Down
6 changes: 3 additions & 3 deletions ugali/isochrone/parsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def _parse(self,filename):
try:
columns = self.columns[self.survey.lower()]
except KeyError as e:
logger.warning('Unrecognized survey: %s'%(survey))
logger.warning('Unrecognized survey: %s'%(self.survey))
raise(e)

# delimiter='\t' is used to be compatible with OldPadova...
Expand Down Expand Up @@ -455,7 +455,7 @@ class Marigo2017(ParsecIsochrone):
(28,('Y',float)),
]),
)

def _parse(self,filename):
"""Reads an isochrone file in the Padova (Marigo et al. 2017)
format. Creates arrays with the initial stellar mass and
Expand All @@ -464,7 +464,7 @@ def _parse(self,filename):
try:
columns = self.columns[self.survey.lower()]
except KeyError as e:
logger.warning('Unrecognized survey: %s'%(survey))
logger.warning('Unrecognized survey: %s'%(self.survey))
raise(e)

kwargs = dict(usecols=list(columns.keys()),dtype=list(columns.values()))
Expand Down
Loading

0 comments on commit 07a93b0

Please sign in to comment.