convert - EranOfek/AstroPack GitHub Wiki

Description:

The convert is a static class that allows for various units conversions. See also the constant static class, celestial.time package, and AstTime class. This file is accessible through the manual package (i.e. manual.convert).

Credit

If you are using this code or products in your scientific publication please give a reference to Ofek (2014; ascl.soft 07005).

License

Unless specified otherwise this code and products are released under the GNU general public license version 3.

Methods and examples

To view all methods available within the convert static class, type "convert." followed by .

General units conversion

The function convert.units can be used for general unit conversion:

[Factor,Out,String]=convert.units('erg','J')
% or to convert a specific value:
[Factor,Out,String]=convert.units('inch','pc',1e5)

To see all options:

help convert.units

Specific conversions

For more specific conversion, you can use the convert.angular to convert angles:

ConvVal=convert.angular('arcsec','rad',1)

convert.energy for energy conversion:

OutE=convert.energy('Hz','erg',1)
OutE=convert.energy('keV','TNT',10)

convert.flux for flux related properties:

% convert 1 mJy at 5000 A to AB mag:
Out=convert.flux(1,'mJy','AB',5000,'A')
% convert 19 ST mag at 1e16 Hz tp photons per Ang per second per cm^2:
Out=convert.flux(19,'STmag','ph/A',1e16,'Hz')
% convert 1e-15 erg/Ang/cm^2/s at 1 eV to photons per Hz per second per cm^2:
Out=convert.flux(1e-15,'cgs/A','ph/Hz',1,'eV')

convert.temp for temperature conversion:

OutTemp=convert.temp(0,'C','K')

The convert.luptitude can be used to convert flux to Luptitude (sinh-based magnitudes). More generaly, convert.flux2mag can be used to convet flux to magnitude or luptitude:

Mag=convert.flux2mag(1,22)

To sum magnitudes:

Sum=convert.sum_mag(rand(10,1))

There are several additional functions for angle conversions: convert.hms2angle, convert.dms2angle, convert.frac2hms, convert.hms2frac. See celestial.coo.convertdms for a more flexible version. Dates related conversion are implemented in convert.date2str, convert.str2date, convert.time, convert.date2jd, convert.jd2date. Additional functions are available in the celestial.time.* package.

Some more examples:

% Convert Julian years to Bessilian years:
convert.time(2000,'J','B')
% Convert Jan 1st 2015 to MJD:
convert.time(2015,'1','MJD')
% convert string date to JD:
convert.time('2015-02-02:10:10:56.112','StrDate','JD')
⚠️ **GitHub.com Fallback** ⚠️