UnitfulAstro.jl icon indicating copy to clipboard operation
UnitfulAstro.jl copied to clipboard

add mas (milliarcsecond) unit

Open aplavin opened this issue 6 years ago • 21 comments

aplavin avatar Jan 29 '19 08:01 aplavin

I'm not sure it's worth a new unit for what is actually a submultiple of another unit. But yes, this is probably used only in Astronomy

giordano avatar Jan 29 '19 09:01 giordano

It is widely used in interferometry (of course). I have mas in my package locally, and find myself using it pretty often. And I'm quite sure the abbreviation doesn't conflict with any other unit.

aplavin avatar Jan 29 '19 10:01 aplavin

Any updates on this? As I understand you are not very opposed to this. And by the way, basically all units are "multiple of another unit", so mas is not special in this sense. In this case I think it would be useful to have other powers-of-ten as well, e.g. muas - but not sure if there is a general method.

aplavin avatar Apr 29 '19 11:04 aplavin

Don't the SI prefixes already do this? m, dm, mm?

m-wells avatar Apr 29 '19 15:04 m-wells

arcsecond belongs to UnitfulAngles so that is where you would need to modify things like using SI prefixes.

If you only want mas then you can do this

using UnitfulAngles
u = UnitfulAngles
mas = 1e-3*u.arcsecond

m-wells avatar Apr 29 '19 15:04 m-wells

As I understand you are not very opposed to this.

Yes, I'm not totally against because I know how much "mas" is used in astronomy, it's just that this isn't a brand-new unit but a power-of-ten multiple of another unit.

I was going to suggest to make arcseconds in UnitfulAngles.jl accept multiples, but I see that the unit there is registered as so that mas wouldn't work anyway. In the end I think I'll merge this in a few days.

giordano avatar Apr 29 '19 16:04 giordano

arcsecond belongs to UnitfulAngles so that is where you would need to modify things like using SI prefixes.

If you only want mas then you can do this

using UnitfulAngles
u = UnitfulAngles
mas = 1e-3*u.arcsecond

It does not seem to work using u_str like 1u"mas".

aplavin avatar Apr 29 '19 18:04 aplavin

u_str only works for registered units.

julia> using Unitful

julia> import UnitfulAngles.arcsecond

julia> @unit mas "mas" MilliArcsecond (1//1000)*arcsecond false
mas

julia> u"mas"
ERROR: LoadError: Symbol mas could not be found in registered unit modules.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] replace_value(::Module, ::Symbol) at /home/mark/.julia/packages/Unitful/W0mMi/src/user.jl:542
 [3] @u_str(::LineNumberNode, ::Module, ::Any) at /home/mark/.julia/packages/Unitful/W0mMi/src/user.jl:495
in expression starting at REPL[7]:1

julia> mas
mas

julia> uconvert(arcsecond, 987.2mas)
0.9872000000000001 ″

here is a link to creating units

m-wells avatar Apr 29 '19 19:04 m-wells

^up

In the end I think I'll merge this in a few days.

Much more has passed :)

aplavin avatar Jun 18 '20 09:06 aplavin

As I understand you are not very opposed to this.

Yes, I'm not totally against because I know how much "mas" is used in astronomy, it's just that this isn't a brand-new unit but a power-of-ten multiple of another unit.

I was going to suggest to make arcseconds in UnitfulAngles.jl accept multiples, but I see that the unit there is registered as so that mas wouldn't work anyway. In the end I think I'll merge this in a few days.

Speaking of multiples of other base cgs/SI units, isn't angstrom already one? I'm all for commonly used astro units like this being supported!

icweaver avatar Jul 08 '20 19:07 icweaver

I'm concerned about adding a special unit when it is explicitly a multiple of a base. Angstrom gets a pass because it is "Angstrom" and not "deci-nano-meter". A clear example of why we want natural prefix behavior would be reporting astrometry using micro-arcseconds or uas/\muas. To this end, I think we just need to alias u"as" as arc-second and the existing prefixes should work out.

mileslucas avatar Jul 08 '20 19:07 mileslucas

Ahh, that's a good point about naming conventions. Would this mean that doing both: 1) aliasing u"as" and 2) creating a mas unit, would be incompatible/break things downstream?

icweaver avatar Jul 08 '20 19:07 icweaver

Would this mean that doing both: 1) aliasing u"as" and 2) creating a mas unit, would be incompatible/break things downstream?

Properly registering u"as" would give us u"mas", as well as any other SI prefix, thus registering u"mas" would be explicitly over-writing. This wouldn't error, I believe, but it's unnecessary and might throw warnings.

mileslucas avatar Jul 08 '20 20:07 mileslucas

Oh, that's so cool. Thanks for the info!

icweaver avatar Jul 08 '20 20:07 icweaver

Hey folks, this definition conflicts with Unitful's "attosecond". See: yakir12/UnitfulAngles.jl#30. Thoughts on the best solution?

cmichelenstrofer avatar Apr 30 '22 23:04 cmichelenstrofer

I'm eager to hear ideas as well. The least elegant solution I can think of is somehow disabling attosecond when UnitfulAngles is loaded.

mileslucas avatar May 02 '22 01:05 mileslucas

das is also problematic.

One option is to add the milliarcsecond and microarcsecond directly (and not allow prefixing). As far as I can tell these are the only two prefixes used with arcsecond. UnitfulAngles.jl would then include all units in this table. Something like:

@unit mas    "mas"    Milliarcsecond    Arcsecond//1_000        false 
@unit μas    "μas"    Microarcsecond    Arcsecond//1_000_000    false 

cmichelenstrofer avatar May 04 '22 01:05 cmichelenstrofer

I think I'm in favor of that, despite my reluctance previously.

mileslucas avatar May 04 '22 16:05 mileslucas

I should have read this thread more carefully. I see this common sentiment and I agree:

I'm not sure it's worth a new unit for what is actually a submultiple of another unit.

I'm concerned about adding a special unit when it is explicitly a multiple of a base.

I took a look at the actual SI Brochure (section 4 Non-SI units that are accepted for use with the SI) and they mention:

For some applications such as in astronomy, small angles are measured in arcseconds (i.e. seconds of plane angle), denoted as or ″, milliarcseconds, microarcseconds and picoarcseconds, denoted mas, μas and pas, respectively, where arcsecond is an alternative name for second of plane angle.

So indeed it seems that different prefixes are used other then milli- and micro- (even the symbol as without prefixes is mentioned).

Nonetheless, if possible we should try to avoid conflict with units in Unitful (however rare). Maybe a better option would be to keep it as an alias (as currently implemented) that displays as as but has a different typed name

@unit as_s            "as"            ArcsecondShort °//3600       true

Then

julia> 10u"as_s"
10 as

julia> 1.2u"μas_s"
1.2 μas

julia> 6.23u"mas_s"
6.23 mas

The typed name could be anything, here I used _s to match the "short" you have in the unit name.

cmichelenstrofer avatar May 05 '22 01:05 cmichelenstrofer

@cmichelenstrofer good idea that compromises different approaches, but I actually think I prefer https://github.com/JuliaAstro/UnitfulAstro.jl/pull/7#issuecomment-1116859954

My thinking is that, I think that if we do

@unit mas    "mas"    Milliarcsecond    Arcsecond//1_000         false 
@unit μas    "μas"    Microarcsecond    Arcsecond//1_000_000     false 
@unit pas    "pas"    Picoarcsecond     Arcsecond//1_000_000_000 false

we simultaneously cover an overwhelming majority of use-cases (e.g., I never using anything more precise than mas) while not sacrificing user interface (having to type _s on every unit is tedious and unintuitive).

This is...not the most beautiful, idiomatic, or elegant solution, but I think it's more important to have something that works good enough rather than trying to perfectly engineer a solution.

mileslucas avatar Sep 24 '22 22:09 mileslucas

FYI I recently created a new package, DimensionfulAngles.jl to treat angles as a dimension and I included the as as well as other astronomy units.

cmichelenstrofer avatar Jan 06 '23 03:01 cmichelenstrofer