Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #25

Merged
merged 2 commits into from
Jul 14, 2023
Merged

Dev #25

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# We recommend specifying your dependencies to enable reproducible builds:
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: requirements.txt
1 change: 0 additions & 1 deletion INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ The latest tagged version of **zCluster** can be installed using ``pip``:

pip install zCluster

Note that you will need to have ``cython`` and ``numpy`` installed already (for the moment).
Other dependencies will be installed by ``pip``.

You may also install using the standard ``setup.py`` script, e.g., as root:
Expand Down
2 changes: 1 addition & 1 deletion bin/zCluster
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def makeParser():
parser.add_argument("-Z", "--z-prior-max", dest="zPriorMax", help="Set maximum redshift of prior.",
default = None)
parser.add_argument("-b", "--brighter-absmag-cut", dest="absMagCut", help="Set bright absolute magnitude cut.",
default = -24.)
default = -24., type = float)
parser.add_argument("-n", "--name", dest="name", help="Find photo-z of only the named cluster in the catalog.")
parser.add_argument("-t", "--templates-directory", dest="templatesDir", help="Specify a directory containing\
a custom set of spectral templates.", default = None)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build-system]
requires = ["numpy", "setuptools", "wheel", "cython"]
requires = ["numpy", "setuptools", "wheel"] #, "cython"]
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from setuptools import Extension
from setuptools.command.install import install
import stat
from Cython.Distutils import build_ext
#from Cython.Distutils import build_ext
import numpy
import versioneer

cmdclass=versioneer.get_cmdclass()
cmdclass['build_ext']=build_ext
#cmdclass['build_ext']=build_ext

setup(name='zCluster',
version=versioneer.get_version(),
Expand All @@ -27,12 +27,12 @@
package_data={'zCluster': ['data/*', 'SED/CWW/*', 'SED/BR07/*', 'SED/EAZY_v1.0/*',
'passbands/*']},
scripts=['bin/zCluster', 'bin/zField', 'bin/zClusterBCG', 'bin/zClusterComparisonPlot'],
ext_modules=[Extension("zClusterCython", ["zCluster/zClusterCython.pyx"], include_dirs=[numpy.get_include()])],
#ext_modules=[Extension("zClusterCython", ["zCluster/zClusterCython.pyx"], include_dirs=[numpy.get_include()])],
install_requires=["astropy >= 4.0",
"numpy >= 1.19",
"matplotlib >= 2.0",
"astLib >= 0.11.7",
"scipy >= 1.0",
"cython",
#"cython",
"requests"]
)
14 changes: 10 additions & 4 deletions zCluster/PhotoRedshiftEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def __init__(self, absMagCut, passbandSet = 'SDSS+Ks', zMin = 0.01, zMax = 3.0,
"""Sets up the stuff we would otherwise calculate every time, i.e., the templates.

"""

# Redshift grid on which to calculate p(z)

if zStep < 0:
print("... WARNING: zStep was negative - forced to be positive")
zStep=abs(zStep)
self.zRange=np.linspace(zMin, zMax, int(((zMax+zStep)-zMin)/zStep))

# Set up passbands
Expand Down Expand Up @@ -423,8 +425,12 @@ def estimateStellarMasses(self, galaxyCatalog, stellarMassModelDir, z = None):
mags=[]
magErrs=[]
for band in self.bands:
mags.append(objDict[band])
magErrs.append(objDict[band+"Err"])
if band in list(objDict.keys()):
mags.append(objDict[band])
magErrs.append(objDict[band+"Err"])
else:
mags.append(99)
magErrs.append(99)
obsSEDDict=astSED.mags2SEDDict(mags, magErrs, self.passbandsList)
distNorm=4*np.pi*np.power(DL*3.08567758e24, 2)
fitResult=sm.fitSEDDictAndCalcStellarMass(obsSEDDict, modelSEDDictList, distNorm)
Expand Down
63 changes: 61 additions & 2 deletions zCluster/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from astropy.coordinates import match_coordinates_sky
from PIL import Image
from PIL import ImageDraw
import zClusterCython
import pylab as plt

#------------------------------------------------------------------------------------------------------------
Expand All @@ -42,6 +41,66 @@ def getPixelAreaDeg2Map(mapData, wcs):

return pixAreasDeg2Map

#---------------------------------------------------------------------------------------------------
def makeDegreesDistanceMap(degreesMap, wcs, RADeg, decDeg, maxDistDegrees):
"""Fills (in place) the 2d array degreesMap with distance in degrees from the given position,
out to some user-specified maximum distance.

Args:
degreesMap (:obj:`np.ndarray`): Map (2d array) that will be filled with angular distance
from the given coordinates. Probably you should feed in an array set to some extreme
initial value (e.g., 1e6 everywhere) to make it easy to filter for pixels near the
object coords afterwards.
wcs (:obj:`astWCS.WCS`): WCS corresponding to degreesMap.
RADeg (float): RA in decimal degrees of position of interest (e.g., object location).
decDeg (float): Declination in decimal degrees of position of interest (e.g., object
location).
maxDistDegrees: The maximum radius out to which distance will be calculated.

Returns:
A map (2d array) of distance in degrees from the given position,
(min x, max x) pixel coords corresponding to maxDistDegrees box,
(min y, max y) pixel coords corresponding to maxDistDegrees box

Note:
This routine measures the pixel scale local to the given position, then assumes that it
does not change. So, this routine may only be accurate close to the given position,
depending upon the WCS projection used.

"""

x0, y0=wcs.wcs2pix(RADeg, decDeg)
ra0, dec0=RADeg, decDeg
ra1, dec1=wcs.pix2wcs(x0+1, y0+1)
xPixScale=astCoords.calcAngSepDeg(ra0, dec0, ra1, dec0)
yPixScale=astCoords.calcAngSepDeg(ra0, dec0, ra0, dec1)

xDistPix=int(round((maxDistDegrees)/xPixScale))
yDistPix=int(round((maxDistDegrees)/yPixScale))

Y=degreesMap.shape[0]
X=degreesMap.shape[1]

minX=int(round(x0))-xDistPix
maxX=int(round(x0))+xDistPix
minY=int(round(y0))-yDistPix
maxY=int(round(y0))+yDistPix
if minX < 0:
minX=0
if maxX > X:
maxX=X
if minY < 0:
minY=0
if maxY > Y:
maxY=Y

xDeg=(np.arange(degreesMap.shape[1])-x0)*xPixScale
yDeg=(np.arange(degreesMap.shape[0])-y0)*yPixScale
for i in range(minY, maxY):
degreesMap[i][minX:maxX]=np.sqrt(yDeg[i]**2+xDeg[minX:maxX]**2)

return degreesMap, [minX, maxX], [minY, maxY]

#------------------------------------------------------------------------------------------------------------
def makeBlankMap(RADeg, decDeg, sizePix, sizeDeg):
"""Makes a square blank map with a WCS.
Expand Down Expand Up @@ -301,7 +360,7 @@ def makeWeightedNz(RADeg, decDeg, catalog, zPriorMax, weightsType, minDistanceMp
else:
areaMap=getPixelAreaDeg2Map(areaMask, wcs)
rDegMap=np.zeros(areaMask.shape)
rDegMap, xRange, yRange=zClusterCython.makeDegreesDistanceMap(rDegMap, wcs, RADeg, decDeg, 2.0)
rDegMap, xRange, yRange=makeDegreesDistanceMap(rDegMap, wcs, RADeg, decDeg, 2.0)
rDegMap=rDegMap[yRange[0]:yRange[1], xRange[0]:xRange[1]]
areaMap=areaMask[yRange[0]:yRange[1], xRange[0]:xRange[1]]*areaMap[yRange[0]:yRange[1], xRange[0]:xRange[1]]
areaMpc2=[]
Expand Down
4 changes: 3 additions & 1 deletion zCluster/retrievers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def getRetriever(database, maxMagError = 0.2):
retrieverOptions={'maxMagError': maxMagError}
elif database.find("DECaLS") != -1:
if database == "DECaLS":
raise Exception("Specify either 'DECaLSDR8' or 'DECaLSDR9' instead of DECaLS")
raise Exception("Specify either 'DECaLSDR8', 'DECaLSDR9', or 'DECaLSDR10' instead of DECaLS")
if database == 'DECaLSDR8':
DR="DR8"
retriever=DECaLSDR8Retriever
Expand All @@ -123,6 +123,8 @@ def getRetriever(database, maxMagError = 0.2):
elif database == "DECaLSDR10":
DR="DR10"
retriever=DECaLSDR10Retriever
else:
raise Exception("Didn't understand DECaLS database choice")
passbandSet='DECaLS'
# For DECaLS, need the bricks files that define survey on the sky
# These were previously included in zCluster, but now we fetch over web and cache
Expand Down
129 changes: 0 additions & 129 deletions zCluster/zClusterCython.pyx

This file was deleted.