How to use splat method in hypothesis

Best Python code snippet using hypothesis

test_core.py

Source:test_core.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from __future__ import print_function3# this is the test function set for splat core functions4# imports - internal5import copy6import glob7import os8# # imports - external9import numpy10from astropy import units as u # standard units11from astropy import constants as const # physical constants in SI units12from astropy.io import fits13from numpy.testing.utils import assert_allclose14# splat functions and constants15from ..initialize import *16from ..utilities import *17from .. import core as splat18#####################19# TESTING FUNCTIONS #20#####################21def test_read():22# readSpectrum23 file = splat.SPLAT_PATH+splat.DATA_FOLDER+'10001_10443.fits'24 dstr = splat.readSpectrum(file)25 assert 'wave' in list(dstr.keys())26 assert 'flux' in list(dstr.keys())27 assert 'noise' in list(dstr.keys())28 assert 'header' in list(dstr.keys())29 assert len(dstr['wave']) > 030 assert len(dstr['flux']) > 031 assert len(dstr['noise']) > 032 assert type(dstr['header']) == fits.header.Header33def test_spectrum_class():34# Spectrum class35# __init__36# __copy__37# copy38# info39# export40# save41 ofile = splat.TMPFILENAME+'.fits'42 s = splat.Spectrum(10001)43 s2 = s.copy()44 assert_allclose(s2.flux[0].value,s.flux[0].value)45 assert isinstance(s.info(printout=False),str)46 if len(glob.glob(ofile)) > 0:47 os.remove(ofile)48 s.export(ofile)49 s2 = splat.Spectrum(filename=ofile)50 assert_allclose(s2.flux[0].value,s.flux[0].value)51 os.remove(ofile)52 s.save(ofile)53 s2 = splat.Spectrum(filename=ofile)54 assert_allclose(s2.flux[0].value,s.flux[0].value)55 os.remove(ofile)56def test_spectrum_trim():57# waverange58# trim59 s = splat.Spectrum(10001)60 assert_allclose(s.waveRange()[0].value,0.6450077295303345)61 un = s.waveRange()[0].unit62 s.trim([1.0,2.0])63 assert_allclose(s.waveRange()[0].value,1.0,rtol=1.e-2)64 assert_allclose(s.waveRange()[1].value,2.0,rtol=1.e-2)65 assert s.waveRange()[0].unit == un66 s.reset()67 assert_allclose(s.waveRange()[0].value,0.6450077295303345)68 assert s.waveRange()[0].unit == un69 70def test_spectrum_math():71# Spectrum class72# __add__73# __sub__74# __mul__75# __div__76 s1 = splat.Spectrum(10001)77 s1.normalize()78 assert_allclose(s1.fluxMax().value,1.)79 s2 = splat.Spectrum(10001)80 s2.normalize()81 assert_allclose(s2.fluxMax().value,1.)82 assert s1.flux.unit == s2.flux.unit83 s3 = s1+s284 assert_allclose(s3.fluxMax().value,2.)85 assert s3.flux.unit == s1.flux.unit86 assert_allclose(s3.snr,s1.snr*(2.**0.5))87 s4 = s3-s188 assert_allclose(s4.fluxMax().value,1.)89 assert s4.flux.unit == s1.flux.unit90 assert_allclose(s4.snr,s1.snr/(3.**0.5))91 s5 = s1*s292 assert_allclose(s5.fluxMax().value,1.)93 assert s5.flux.unit == s1.flux.unit**294 assert s5.snr < s1.snr95#96# NOTE: THIS IS NOT WORKING AT THE MOMENT97#98 s6 = s3/s199 assert_allclose(s6.fluxMax().value,2.)100 assert s6.flux.unit == s1.flux.unit/s1.flux.unit101 102def test_spectrum_scaling():103# normalize104# scale105# computeSN106# fluxCalibrate107# fluxMax108# reset109 s = splat.Spectrum(10001)110 omx = s.fluxMax().value111 snr0 = s.computeSN()112 s.normalize()113 assert_allclose(s.fluxMax().value,1.)114 assert_allclose(snr0,s.computeSN())115 assert s.fscale == 'Normalized'116 s.scale(2.0)117 assert_allclose(s.fluxMax().value,2.)118 assert_allclose(snr0,s.computeSN())119 assert s.fscale == 'Scaled'120 s.fluxCalibrate('2MASS J',15.0)121 assert s.fscale == 'Apparent'122 s.fluxCalibrate('2MASS J',15.0,apparent=True)123 assert s.fscale == 'Apparent'124 s.fluxCalibrate('2MASS J',15.0,absolute=True)125 assert s.fscale == 'Absolute'126 mag,mag_e = splat.filterMag(s,'2MASS J')127 assert_allclose(mag,15.0)128 s.reset()129 assert_allclose(s.fluxMax().value,omx)130 assert_allclose(snr0,s.computeSN())131 132def test_spectrum_conversions():133# toFnu134# toFlam135# surface136# brightnessTemperature137# temperature138 s = splat.Spectrum(10001)139 bunit = s.flux.unit140 omx = s.fluxMax()141 assert s.flux.unit.is_equivalent(u.watt/u.m**3)142 s.flamToFnu()143 assert s.flux.unit.is_equivalent(u.Jy)144 s.fnuToFlam()145 assert s.flux.unit.is_equivalent(u.watt/u.m**3)146 s.fluxCalibrate('2MASS J',15.0,absolute=True)147 assert s.fscale == 'Absolute'148 mx = s.fluxMax()149 s.surface(0.1)150 assert s.fscale == 'Surface'151 assert_allclose(s.fluxMax()/mx,((100.*u.pc/const.R_sun)**2).to(u.m/u.m))152 s.brightnessTemperature()153 assert s.fscale == 'Temperature'154 assert s.funit == u.K155 s.reset()156 assert s.flux.unit == bunit157 assert s.fluxMax() == omx158 159def test_spectrum_plot():160# plot161 file = splat.TMPFILENAME+'.png'162 s = splat.Spectrum(10001)163 s.plot(file=file)164 assert os.access(file,os.R_OK)165 os.remove(file)166def test_spectrum_smooth():167# smooth168# _smoothToResolution169# _smoothToSlitPixelWidth170# _smoothToSlitWidth171 s = splat.Spectrum(10001)172 res0 = copy.deepcopy(s.resolution)173 slit0 = copy.deepcopy(s.slitwidth)174 slitp0 = copy.deepcopy(s.slitpixelwidth)175 assert slit0.unit == u.arcsec176 s.smooth(resolution = 50)177 assert_allclose(s.resolution,50)178 assert_allclose(s.slitwidth,slit0*res0/50)179 assert_allclose(s.slitpixelwidth,slitp0*res0/50)180 s.reset()181 s.smooth(slitwidth = 3*u.arcsec)182 assert_allclose(s.slitwidth,3.*u.arcsec)183 assert_allclose(s.resolution,res0*(slit0/s.slitwidth).value)184 assert_allclose(s.slitpixelwidth,slitp0*(s.slitwidth/slit0).value)185 s.reset()186 s.smooth(slitwidth = 3.)187 assert_allclose(s.slitwidth,3.*u.arcsec)188 assert_allclose(s.resolution,res0*(slit0/s.slitwidth).value)189 assert_allclose(s.slitpixelwidth,slitp0*(s.slitwidth/slit0).value)190 s.reset()191 s.smooth(slitpixelwidth = 5)192 assert_allclose(s.slitpixelwidth,5)193 assert_allclose(s.resolution,res0*slitp0/s.slitpixelwidth)194 assert_allclose(s.slitwidth,slit0*s.slitpixelwidth/slitp0)195 s.reset()196 assert_allclose(s.slitpixelwidth,slitp0)197 assert_allclose(s.resolution,res0)198 assert_allclose(s.slitwidth,slit0)199 200def test_classify_gravity():201# classifyByTemplate202# classifyGravity203 sp = splat.Spectrum(10001) 204 grav = splat.classifyGravity(sp)205 assert grav == 'FLD-G'206 grav = splat.classifyGravity(sp,allscores=True)207 assert isinstance(grav,dict)208 assert grav['gravity_class'] == 'FLD-G'209 #assert grav['spt'] == 'L4.0'210 grav = splat.classifyGravity(sp,allscores=True,spt='L5')211 assert grav['gravity_class'] == 'FLD-G'212 assert grav['spt'] == 'L5.0'213 sp = splat.getSpectrum(name='G 196-3B')[0]214 grav = splat.classifyGravity(sp,allscores=True)215 assert grav['gravity_class'] == 'VL-G'216 assert grav['spt'] == 'L3.0'217 assert grav['score'] >= 2.218def test_compare():219# compareSpectra220 from .. import model as spm221 sp = splat.Spectrum(10001)222 mdl = spm.getModel(teff=2000,logg=5.0)223 chi, scale = splat.compareSpectra(sp,mdl,mask_standard=True,stat='chisqr')224# sys.stderr.write('\nScaling model: chi^2 = {}, scale = {}'.format(chi,scale))225# sys.stderr.write('\n...compareSpectra successful\n'.format(chi,scale))226 227 228def test_indices():229# measureIndex230# measureIndexSet231# classifyByIndex232 sp = splat.Spectrum(10001)233 ind = splat.measureIndexSet(sp,set='burgasser')234 assert 'CH4-H' in list(ind.keys())235 assert_allclose(ind['CH4-H'][0],1.04,rtol=ind['CH4-H'][1])236 for st in list(splat.INDICES_SETS.keys()):237 ind = splat.measureIndexSet(sp,set=st)238 assert len(ind) > 0239 240 spt, spt_e = splat.classifyByIndex(sp,set='burgasser',string=False)241 assert_allclose(spt,26.0,rtol=spt_e)242 spt, spt_e = splat.classifyByIndex(sp,set='reid',string=False)243 assert_allclose(spt,24.6,rtol=spt_e)244 spt, spt_e = splat.classifyByIndex(sp,set='allers',string=False)245 assert_allclose(spt,24.5,rtol=spt_e)246 247def test_standards():248# initiateStandards249# getStandard250# classifyByStandard251 std = splat.getStandard('M1.0')252 assert 'M1.0' in list(splat.STDS_DWARF_SPEX.keys())253 assert std.name == 'Gl424'254 assert std.spex_type == 'M1.0'255 std = splat.getStandard('esdM5.0')256 assert 'esdM5.0' in list(splat.STDS_ESD_SPEX.keys())257 assert std.name == 'LP 589-7'258 assert std.opt_type == 'esdM5'259 std = splat.getStandard(16,sd=True)260 assert 'sdM6.0' in list(splat.STDS_SD_SPEX.keys())261 assert std.name == 'LHS 1074'262 assert std.opt_type == 'sdM6'263 splat.initiateStandards()264 for typ in list(splat.STDS_DWARF_SPEX_KEYS.keys()):265 assert type(splat.STDS_DWARF_SPEX[typ]) == splat.Spectrum266 splat.initiateStandards(sd=True)267 for typ in list(splat.STDS_SD_SPEX_KEYS.keys()):268 assert type(splat.STDS_SD_SPEX[typ]) == splat.Spectrum269 splat.initiateStandards(esd=True)270 for typ in list(splat.STDS_ESD_SPEX_KEYS.keys()):271 assert type(splat.STDS_ESD_SPEX[typ]) == splat.Spectrum272 sp = splat.Spectrum(10001)273 spt, spt_e = splat.classifyByStandard(sp,method='kirkpatrick',verbose=True)274 assert spt == 'L5.0'275 spt, spt_e = splat.classifyByStandard(sp,method='kirkpatrick',string=False)276 assert spt == 25.0277 spt, spt_e = splat.classifyByStandard(sp,sptrange=['M1.0','M8.0'],verbose=True)278 assert spt == 'M8.0'279 spt, spt_e = splat.classifyByStandard(sp,sd=True)280 assert spt == 'sdL0.0'281 spt, spt_e = splat.classifyByStandard(sp,esd=True)282 assert spt == 'esdM5.0'283 file = splat.TMPFILENAME+'.png'284 spt, spt_e = splat.classifyByStandard(sp,method='kirkpatrick',plot=True,file=file)285 assert os.access(file,os.R_OK)286 os.remove(file)287 288def test_getspectrum():289# getSpecturm290# get random spectrum291 sp = splat.getSpectrum(lucky=True,published=True)292 assert type(sp) == list293 assert type(sp[0]) == splat.Spectrum294 print(type(sp[0]))295# get spectrum by shortname296 sp = splat.getSpectrum(shortname='0559-1404')297 assert sp[0].shortname == 'J0559-1404'298# get spectrum by source key299 sp = splat.getSpectrum(source_key=10001) 300 assert int(sp[0].source_key) == 10001301 assert sp[0].shortname == 'J0000+2554'302# get spectrum by data key303 sp = splat.getSpectrum(data_key=10001)304 assert int(sp[0].data_key) == 10001305 assert sp[0].shortname == 'J0539-0059'306# get spectrum in a range of subtypes307 sp = splat.getSpectrum(spt=['L5','T5'],spt_type='spex',lucky=True)[0]308 n = splat.typeToNum(sp.spex_type)309 assert (n>=25 and n<=35)310# make sure getSpectrum fails properly311 sp = splat.getSpectrum(shortname='9999')312 assert len(sp) == 0313# incomplete tests314def test_database():315# fetchDatabase316# keySource317# keySpectrum318# searchLibrary319 s = splat.searchLibrary(published=True)320 assert len(s) > 1500321 s = splat.searchLibrary(young=True,output='DATA_FILE')322 assert '.fits' in s[0]323def test_masking():324# _generateMask325 pass326def test_classify_template():327# classifyByTemplate328 pass329def test_ews():330# measureEW331# measureEWSet332 pass333def test_metallicity():334# metallicity...

Full Screen

Full Screen

test_utilities.py

Source:test_utilities.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from __future__ import print_function3# this is the test function set for splat utility functions4# imports - internal5import copy6# # imports - external7import numpy8from astropy import units as u # standard units9from astropy import constants as const # physical constants in SI units10from astropy import coordinates as coord # coordinate conversion11from astropy.io import fits12from numpy.testing.utils import assert_allclose13# splat functions and constants14from ..initialize import *15from ..utilities import *16from .. import core as splat17#import splat as splat18# things to test19# isNumber 20#####################21# TESTING FUNCTIONS #22#####################23def test_online_access():24# checkFile25# checkAccess26# checkLocal27# checkOnline28# checkOnlineFile29 assert splat.checkOnline()30 assert splat.checkOnlineFile()31 assert len(splat.checkOnlineFile('Reference/SpectralModels/'))>032 assert len(splat.checkOnlineFile('Reference/Spectra/11221_10235.fits'))>033 assert len(splat.checkOnlineFile('Reference/Spectra/11220_10166.fits'))>034 assert len(splat.checkLocal('Reference/SpectralModels/'))>035 assert len(splat.checkLocal('Reference/Spectra/11221_10235.fits'))>036 assert len(splat.checkLocal('Reference/Spectra/11220_10166.fits'))==037 assert splat.checkFile('11221_10235.fits')38 assert splat.checkFile('11220_10166.fits')39 assert splat.checkAccess()40def test_isnumber():41# checkKeys42 assert splat.isNumber(3)43 assert splat.isNumber(3.0)44 assert splat.isNumber(3.0*u.arcsec)45 assert splat.isNumber('3')46 assert not splat.isNumber('hello')47 assert not splat.isNumber(numpy.nan)48 assert not splat.isNumber(True)49def test_coordinate_conversion():50# coordinateToDesignation 51# designationToCoordinate 52# designationToShortName 53# properCoordinates 54 d = 'J05591914-1404488'55 assert splat.designationToShortName(d) == 'J0559-1404'56 c = splat.designationToCoordinate(d)57 assert isinstance(c,coord.sky_coordinate.SkyCoord)58 assert_allclose(c.ra.value,89.82975,rtol=1.e-5)59 assert_allclose(c.dec.value,-14.08002,rtol=1.e-5)60 c1 = splat.properCoordinates(d)61 assert isinstance(c1,coord.sky_coordinate.SkyCoord)62 assert_allclose(c1.ra.value,c.ra.value,rtol=1.e-5)63 assert_allclose(c1.dec.value,c.dec.value,rtol=1.e-5)64 d1 = splat.coordinateToDesignation(c)65 assert splat.designationToShortName(d1) == 'J0559-1404'66 c2 = splat.designationToCoordinate(d1)67 assert isinstance(c2,coord.sky_coordinate.SkyCoord)68 assert_allclose(c2.ra.value,c.ra.value,rtol=1.e-5)69 assert_allclose(c2.dec.value,c.dec.value,rtol=1.e-5) 70 c3 = splat.properCoordinates('05 59 19.14 -14 04 48.8') 71 assert_allclose(c3.ra.value,c.ra.value,rtol=1.e-4)72 assert_allclose(c3.dec.value,c.dec.value,rtol=1.e-4) 73 c4 = splat.properCoordinates('05:59:19.14 -14:04:48.8') 74 assert_allclose(c4.ra.value,c.ra.value,rtol=1.e-4)75 assert_allclose(c4.dec.value,c.dec.value,rtol=1.e-4) 76 c5 = splat.properCoordinates('05h59m19.14s -14d04m48.8s') 77 assert_allclose(c5.ra.value,c.ra.value,rtol=1.e-4)78 assert_allclose(c5.dec.value,c.dec.value,rtol=1.e-4) 79 c6 = splat.properCoordinates([89.82975,-14.08002]) 80 assert_allclose(c6.ra.value,c.ra.value,rtol=1.e-4)81 assert_allclose(c6.dec.value,c.dec.value,rtol=1.e-4) 82def test_type_conversion():83# typeToNum 84 assert splat.typeToNum('L5') == 25.85 assert splat.typeToNum(25.0) == 'L5.0'86 splat.typeToNum(25.,subclass='sd') == 'sdL5.0'87 assert splat.typeToNum('K0') == 0.88 assert splat.typeToNum('m0') == 10.89 assert splat.typeToNum('L0') == 20.90 assert splat.typeToNum('t0') == 30.91 assert splat.typeToNum('Y0') == 40.92# assert splat.typeToNum('A0') == numpy.nan93 assert splat.typeToNum(25.,error=':') == 'L5.0:'94 assert splat.typeToNum(25.,uncertainty=1.2) == 'L5.0:'95 assert splat.typeToNum(25.,lumclass='I') == 'L5.0 I'96 assert splat.typeToNum(25.,peculiar=True) == 'L5.0p'97 assert splat.typeToNum(25.,ageclass='beta',uncertainty=2.5) == 'L5.0beta::'98 t = splat.typeToNum([12,18,26])99 assert isinstance(t,list)100 assert 'M8.0' in t101def test_date_conversion():102# properdate103 assert splat.properDate('20050523') == '2005-05-23'104 assert splat.properDate(20050523) == '2005-05-23'105 assert splat.properDate('050523') == '2005-05-23'106 assert splat.properDate(990523) == '1999-05-23'107 assert splat.properDate('5/23/2005') == '2005-05-23'108 assert splat.properDate('5/23/05') == '2005-05-23'109 assert splat.properDate('5/23/85') == '1985-05-23'110 assert splat.properDate('23 May 2005') == '2005-05-23'111 assert splat.properDate('2005 May 23') == '2005-05-23'112 assert splat.properDate('20050523',output='YYYYMMDD') == '20050523'113 assert splat.properDate('20050523',output='YYMMDD') == '050523'114 assert splat.properDate('20050523',output='MM/DD/YY') == '05/23/05'115 assert splat.properDate('20050523',output='MM/DD/YYYY') == '05/23/2005'116 assert splat.properDate('20050523',output='YYYY/MM/DD') == '2005/05/23'117 assert splat.properDate('20050523',output='DD/MM/YYYY') == '23/05/2005'118 assert splat.properDate('20050523',output='DD MMM YYYY') == '23 May 2005'119 assert splat.properDate('20050523',output='YYYY MMM DD') == '2005 May 23'120def test_stats():121# distributionStats 122# weightedMeanVar 123 values = [0.3,0.5,2.4,6.1,5.6,3.2,1.8,5.0,2.2,-4.5,10.2,-0.5,numpy.nan]124 weights = [1,1,2,3,3,2,2,3,2,0,4,0,0]125 x = splat.distributionStats(values)126 assert isinstance(x,numpy.ndarray)127 assert_allclose(x[1],numpy.nanmedian(values))128 x1 = splat.distributionStats(values,sigma=1.5)129 assert x[0] >= x1[0]130 assert x[-1] <= x1[-1]131 assert x[1] == x1[1]132 x2 = splat.distributionStats(values,q=[0.25,0.5,0.75])133 assert x[0] <= x2[0]134 assert x[-1] >= x2[-1]135 assert x[1] == x2[1]136 x3 = splat.distributionStats(values,weights=weights)137 assert x[0] <= x3[0]138 assert x[-1] <= x3[-1]139 assert x[1] <= x3[1]140 weights0 = numpy.ones(len(weights))141 x = splat.weightedMeanVar(values,weights0)142 assert isinstance(x,tuple)143 x2 = splat.weightedMeanVar(values,weights)144 assert x2[0] > x[0]145 assert x2[-1] < x[-1]146 147# incomplete tests148def test_check_keys():149# checkKeys...

Full Screen

Full Screen

EffectManager.py

Source:EffectManager.py Github

copy

Full Screen

1from pandac.PandaModules import *2from pandac.PandaModules import *3from direct.showbase.DirectObject import DirectObject4from direct.interval.IntervalGlobal import *5from toontown.battle.BattleProps import *6from toontown.battle import MovieUtil7class EffectManager(DirectObject):8 def __init__(self):9 self.effectList = []10 def delete(self):11 for effect in effectList:12 self.__removeEffect(effect)13 def addSplatEffect(self, spawner, splatName = 'splat-creampie', time = 1, size = 6, parent = render):14 splat = globalPropPool.getProp(splatName)15 splatSeq = Sequence()16 splatType = globalPropPool.getPropType(splatName)17 splatShow = Func(self.__showProp, splat, size, parent, spawner.getPos(parent))18 splatAnim = ActorInterval(splat, splatName)19 splatHide = Func(MovieUtil.removeProp, splat)20 splatRemove = Func(self.__removeEffect, splatSeq)21 splatSeq.append(splatShow)22 splatSeq.append(splatAnim)23 splatSeq.append(splatHide)24 splatSeq.append(splatRemove)25 splatSeq.start()26 self.effectList.append(splatSeq)27 def __showProp(self, prop, size, parent, pos):28 prop.reparentTo(parent)29 prop.setScale(size)30 prop.setBillboardPointEye()31 prop.setPos(pos + Vec3(0, 0, size / 2))32 def __removeEffect(self, effect):33 if effect.isPlaying():34 effect.finish()35 self.effectList.remove(effect)36 effect = None...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful