Skip to content

Commit

Permalink
Renamed test_conda_pyimfit.py to test_pyimfit_install.py, made it mor…
Browse files Browse the repository at this point in the history
…e general script that downloads

example directory if it is not found locally.
  • Loading branch information
perwin committed Jun 16, 2024
1 parent ddfd2a4 commit 05b46cf
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 37 deletions.
11 changes: 6 additions & 5 deletions conda/howto_build-for-conda.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
SIMPLE NOTES ON HOW TO BUILD CONDA PACKAGES WITH RATTLER-BUILD

Note that <some-appropriate-environment> should probably be an environment with the
"nomkl" meta-package installed.

$ conda activate <some-appropriate-environment>

The following will generate packages for Python 3.8--3.12

$ rattler-build build --recipe ./rattler_setup --variant-config ./rattler_setup/variant_config.yaml

Generated conda packages will be in a subdirectory of output/
Doing this on MacBook Pro 2019
output/osx-64 -- for Intel (x86-64) binaries
Doing this in Ubuntu VM on MBPro 2019
output/linux-64 -- for Intel Linux binaries


HOW TO UPLOAD:
Expand All @@ -21,7 +19,10 @@ Activate a conda environment that has the anaconda client installed, then log in

Use "anaconda upload" and the names of the .conda (or .tar.bz2) files

MacOS Intel:
% anaconda upload output/osx-86/pyimfit-*.conda [change output subdirectory name as appropriate]
Ubuntu VM (Intel):
% anaconda upload output/linux-64/pyimfit-*.conda [change output subdirectory name as appropriate]

These will be uploaded to https://anaconda.org/perwin/pyimfit

Expand Down
24 changes: 0 additions & 24 deletions conda/test_conda_pyimfit.py

This file was deleted.

68 changes: 68 additions & 0 deletions conda/test_pyimfit_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3

# Simple test script to see if we can a) import pymfit; and b) run a simple fit
# using it. Uses files in the default Imfit examples/ directory (downloads and
# unpacks this if it isn't in the lcoal directory).

import sys, os, tarfile
import requests
import pyimfit
from astropy.io import fits


# UPDATE THIS TO POING TO WHERE THE IMFIT-EXAMPLES DIRECTORY IS LOCATED
BASE_DIR_ERWIN = "/Users/erwin/coding/imfit/examples/bob/"
EXAMPLES_URL = "https://www.mpe.mpg.de/~erwin/resources/imfit/imfit_examples.tar.gz"

IMAGE_FILE = "ic3478rss_256.fits"
CONFGI_FILE = "config_sersic_ic3478_256.dat"



def main( argv ):
# By default, we look for a pre-existing Imfit examples/ subdirectory in the current directory
# If not found, we look in BASE_DIR_ERWIN; if not found there, we download and unpack it
# from the Imfit webpage at MPE
if os.path.exists("./examples"):
baseDir = "./examples/"
elif os.path.exists(BASE_DIR_ERWIN):
baseDir = BASE_DIR_ERWIN
else:
print("ERROR: Unable to locate pre-existing examples directory.")
print("Downloading and unpacking examples directory...")
r = requests.get(EXAMPLES_URL, allow_redirects=True)
open('examples.tar.gz', 'wb').write(r.content)
tar = tarfile.open("examples.tar.gz")
tar.extractall(filter='data')
tar.close()
baseDir = "./examples/"
print("Done.")

imageFile = baseDir + IMAGE_FILE
configFile = baseDir + CONFGI_FILE

print("\nStarting test...")
vinfo = sys.version_info
print("Python version {0}.{1}".format(vinfo[0], vinfo[1]))
print("PyImfit version {0}".format(pyimfit.__version__))

filesExist = True
if not os.path.exists(imageFile):
print("ERROR: Unable to locate image file (path = %s" % imageFile)
filesExist = False
if not os.path.exists(configFile):
print("ERROR: Unable to locate Imfit config file (path = %s" % configFile)
filesExist = False

if filesExist:
image_data = fits.getdata(imageFile)
model_desc = pyimfit.ModelDescription.load(configFile)
imfit_fitter = pyimfit.Imfit(model_desc)
print("Doing the fit...")
fit_result = imfit_fitter.fit(image_data, gain=4.725, read_noise=4.3, original_sky=130.14)
print(fit_result)
print("Done!\n")


if __name__ == '__main__':
main(sys.argv)
13 changes: 7 additions & 6 deletions howto_new_distribution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ Working by default in ~/coding/pyimfit on Mac.
A. [vm] cd /home/vagrant/build/pyimfit
B. [vm] git pull origin master [if necessary]
C. [vm] cd conda
D. [vm] rattler-build build --recipe ./rattler_setup --variant-config ./rattler_setup/variant_config.yaml
E. [vm] cd output
F. [vm] tar -cf linux-64.tar linux-64 && gzip linux-64.tar
G. [vm] cp linux-64.tar.gz /vagrant/transfer/
H. [mac] cd /Users/erwin/coding/pyimfit/conda
I. [mac] tar -xf ~/vagrant/iraf/transfer/linux-64.tar.gz -C output
D. [vm] rm -rf output
E. [vm] rattler-build build --recipe ./rattler_setup --variant-config ./rattler_setup/variant_config.yaml
F. [vm] cd output
G. [vm] tar -cf linux-64.tar linux-64 && gzip linux-64.tar
H. [vm] cp linux-64.tar.gz /vagrant/transfer/
I. [mac] cd /Users/erwin/coding/pyimfit/conda
J. [mac] tar -xf ~/vagrant/iraf/transfer/linux-64.tar.gz -C output

12. Upload conda packages to anaconda
A. conda activate
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Pip requirements.txt file for PyImfit
# Pip requirements.txt file for PyImfit, including for testing
numpy
scipy
pytest
requests

# stuff to avoid possible conflicts involving Sphinx and docutils-0.18 on readthedocs.org
sphinx<4.0
Expand Down

0 comments on commit 05b46cf

Please sign in to comment.